First page Back Continue Last page Overview Graphics
More examples of reflection / monkey-patching:
String#disemvowel, Enumerable#sum
class Hash
def method_missing(meth,*args)
if /=$/=~(meth=meth.id2name) then
self[meth[0...-1]] = (args.length<2 ? args[0] : args)
else
self[meth]
end
end
end
x = { :name => 'Gavin', :age => 31 }
x.weight = 171
x.feet = ['left','right']