I would like to add method nil_or_empty?
to all classes, therefore I define
module ObjectExtensions
def nil_or_empty?
return self.nil? || (self.respond_to?('empty?') && self.empty?)
end
end
::Object.class_eval { include ::ObjectExtensions }
It works fine in a simple Ruby script
p nil.nil_or_empty? #=> true
p ''.nil_or_empty? #=> true
p [].nil_or_empty? #=> true
p 0.nil_or_empty? #=> false
However, when I add it to my library file lib/extensions.rb
in a Rails 3 app, it seems to be not added
NoMethodError (undefined method `nil_or_empty?' for nil:NilClass):
app/controllers/application_controller.rb:111:in `before_filter_test'
I do load the library file (all other extensions from that file are working fine) and
# config/application.rb
# ...
config.autoload_paths << './lib'
Where am I wrong?