Class: Object
- Inherits:
- BasicObject
- Includes:
- InstanceExecHelper
- Defined in:
- lib/extensions/object.rb,
lib/extensions/object.rb
Defined Under Namespace
Modules: InstanceExecHelper
Instance Method Summary collapse
-
#instance_exec(*args, &block) ⇒ Object
instance_exec method evaluates a block of code relative to the specified object, with parameters whom come from outside the object.
- #metaclass ⇒ Object
Instance Method Details
#instance_exec(*args, &block) ⇒ Object
instance_exec method evaluates a block of code relative to the specified object, with parameters whom come from outside the object.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/extensions/object.rb', line 11 def instance_exec(*args, &block) begin old_critical, Thread.critical = Thread.critical, true n = 0 n += 1 while respond_to?(mname="__instance_exec#{n}") InstanceExecHelper.module_eval{ define_method(mname, &block) } ensure Thread.critical = old_critical end begin ret = send(mname, *args) ensure InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil end ret end |
#metaclass ⇒ Object
4 5 6 |
# File 'lib/extensions/object.rb', line 4 def class << self; self; end end |