/ Published in: Ruby

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# 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
Comments
