2014-11-21 60 views
0

Sinatra寶石有production?development?功能, 如何檢查腳本是有史以來需要Sinatra 或者有production?development?函數曾經定義?如何檢查是否一個Ruby的功能(不是方法)存在

可能是更好的解釋:

script1.rb: 
# there is possibility that this script contains "require 'sinatra'" 
# note that sinatra defines 'production?' and 'development?' function 

script2.rb: 
# there is possibility that this script already has defining 'production?' function 

script3.rb: 
require_relative 'script1' 
require_relative 'script2' 
... 
require_relative 'scriptX' 
# in this script, how to know if there are at least one script that has already defining 'production?' function? 
+1

你調用的函數實際上是方法。 – 2014-11-21 03:06:43

+0

'對象'的方法? – Kokizzu 2014-11-21 03:08:25

+0

Ruby中沒有函數,只有實例方法。你能澄清你的問題嗎?你在說「Proc」嗎? – 2014-11-21 10:39:34

回答

0

啊哈!使用defined?

require 'ap' 

ap defined? production? 
# nil 

def production? 
end 

ap defined? production? 
# 'method' 
相關問題