Tutorial by Examples

Monkey patching is the modification of classes or objects outside of the class itself. Sometimes it is useful to add custom functionality. Example: Override String Class to provide parsing to boolean class String def to_b self =~ (/^(true|TRUE|True|1)$/i) ? true : false end end A...
Like patching of classes, you can also patch single objects. The difference is that only that one instance can use the new method. Example: Override a string object to provide parsing to boolean s = 'true' t = 'false' def s.to_b self =~ /true/ ? true : false end >> s.to_b =&...

Page 1 of 1