Setting Core Objects’ Methods in RoR

Aug 09
2008

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.

Comments are closed.

Calendar

August 2008
M T W T F S S
« Jul   Sep »
 123
45678910
11121314151617
18192021222324
25262728293031

Tags