2011-01-10 24 views

回答

25

您不必運行Rails使用

require 'active_support/all' 

,或者如果你只是想要一個特定的擴展,像blank?字符串然後就

require 'active_support/core_ext/string' 

looked uppresent?和它的實際定義as

def present? 
    !blank? 
end 

blank defined作爲

def blank? 
    respond_to?(:empty?) ? !!empty? : !self 
end 
+3

作爲tokland說下面你可以更具體些:需要「active_support/core_ext /對象/空白」 – 2011-01-10 21:01:39

8

您可以要求ActiveSupport的特定功能。在這種情況下:

require 'active_support/core_ext/object/blank' 
[].present? #=> false