Class: Object

Inherits:
BasicObject
Extended by:
Pancake::Hooks::InheritableInnerClasses
Defined in:
lib/pancake/core_ext/object.rb,
lib/pancake/core_ext/object.rb

Instance Method Summary collapse

Methods included from Pancake::Hooks::InheritableInnerClasses

before_inner_class_inheritance, extended, inheritable_inner_classes, inherited

Instance Method Details

#instance_exec(*args, &block) ⇒ Object

Like instace_eval but allows parameters to be passed.



11
12
13
14
15
16
17
18
19
20
# File 'lib/pancake/core_ext/object.rb', line 11

def instance_exec(*args, &block)
  mname = "__instance_exec_#{Thread.current.object_id.abs}_#{object_id.abs}"
  Object.class_eval{ define_method(mname, &block) }
  begin
    ret = send(mname, *args)
  ensure
    Object.class_eval{ undef_method(mname) } rescue nil
  end
  ret
end