instance method
instance_exec
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
instance_exec(*args, &block)
Evaluate the block with the given arguments within the context of this object, so self is set to the method receiver.
From Mauricio’s eigenclass.org/hiki/bounded+space+instance_exec
Parameters
-
argsrest -
blockblock
Source
# File activesupport/lib/active_support/core_ext/object/extending.rb, line 63
def instance_exec(*args, &block)
begin
old_critical, Thread.critical = Thread.critical, true
n = 0
n += 1 while respond_to?(method_name = "__instance_exec#{n}")
InstanceExecMethods.module_eval { define_method(method_name, &block) }
ensure
Thread.critical = old_critical
end
begin
send(method_name, *args)
ensure
InstanceExecMethods.module_eval { remove_method(method_name) } rescue nil
end
end
Defined in activesupport/lib/active_support/core_ext/object/extending.rb line 63
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Object