Module: CoreEx::Object::InstanceEvalWithArgs

Included in:
Object
Defined in:
lib/core_ex/object/instance_eval_with_args.rb

Instance Method Summary collapse

Instance Method Details

#instance_eval_with_args(*args, &block) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/core_ex/object/instance_eval_with_args.rb', line 15

def instance_eval_with_args ( *args, &block )
  raise ArgumentError, "no block given" if block.nil?
  method_name = :"instance_eval_temporary_method#{object_id}.#{@@seed}"
  @@seed += 1
  define_singleton_method(method_name, &block)
  begin
    result = __send__(method_name, *args)
  ensure
    undef_singleton_method(method_name)
  end
  result
end