From: Phrogz Date: 2010-03-31T13:31:33+09:00 Subject: Pop Quiz: aliasing versus wrapping Below are two files that differ only in the 2nd line of code in each. Can you guess what difference they will reveal? I must admit I was surprised when I ran into this. $ cat alias.rb class Object alias_method :to_js, :inspect end class Array def to_js; "[#{map{|o|o.to_js}.join(',')}]"; end end class Hash def to_js "{#{map{|k,v| "#{k.to_s.to_js}:#{v.to_js}" }.join(',')}}" end end [ 1, [true], {a:"foo"} ].each{ |o| puts o.to_js } $ cat wrapped.rb class Object def to_js; inspect; end end class Array def to_js; "[#{map{|o|o.to_js}.join(',')}]"; end end class Hash def to_js "{#{map{|k,v| "#{k.to_s.to_js}:#{v.to_js}" }.join(',')}}" end end [ 1, [true], {a:"foo"} ].each{ |o| puts o.to_js }