Setting Core Objects’ Methods in RoR
Aug 09
2008
2008
Comments Off
mkdir -p RAILS_ROOT/vendor/plugins/core_methods
mkdir -p RAILS_ROOT/vendor/plugins/core_methods/init.rb
The content of init.rb:
module Rails empty_and_nil = %q{def empty_and_nil; self.empty?? nil : self end} Array.send :class_eval, empty_and_nil Hash.send :class_eval, empty_and_nil end
The namespace Rails isn’t necessary, it’s a cosmetic feature.