Revision: 42540
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 6, 2011 23:25 by Shamaoke
Initial Code
# encoding: utf-8 module ObjectExtensions def execute(&block) Extension.new.execute(&block) end end class Extension def execute(&block) self.instance_eval(&block) end def one; puts 'one' end def two; puts 'two' end def three; puts 'three' end end Object.__send__(:include, ObjectExtensions) one rescue puts 'boom!' #=> boom! two rescue puts 'boom too!' #=> boom too! three rescue puts 'boom three!' #=> boom three! execute do one #=> one two #=> two three #=> three four rescue puts 'boom four!' #=> boom four! end
Initial URL
Initial Description
Initial Title
Execute an instance method of Object and call in its block instance methods of another object
Initial Tags
ruby
Initial Language
Ruby