Module: Waves::Ext::Object
- Included in:
- Object
- Defined in:
- lib/waves/ext/object.rb
Instance Method Summary collapse
-
#instance_exec(*args, &block) ⇒ Object
This is an extremely powerful little function that will be built-in to Ruby 1.9.
Instance Method Details
#instance_exec(*args, &block) ⇒ Object
This is an extremely powerful little function that will be built-in to Ruby 1.9. This version is from Mauricio Fernandez via ruby-talk. Works like instance_eval except that you can pass parameters to the block.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/waves/ext/object.rb', line 8 def instance_exec(*args, &block) mname = "__instance_exec_#{Thread.current.object_id.abs}" class << self; self end.class_eval{ define_method(mname, &block) } begin ret = send(mname, *args) ensure class << self; self end.class_eval{ undef_method(mname) } rescue nil end ret end |