Module: ContextEval

Defined in:
lib/context_eval.rb,
lib/context_eval/version.rb

Constant Summary collapse

VERSION =
'0.1.0'

Instance Method Summary collapse

Instance Method Details

#context_eval(*args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/context_eval.rb', line 4

def context_eval(*args)
  arg = args.shift

  case arg
  when Symbol
    send(arg)
  when Proc
    if arg.arity == 0
      instance_exec(&arg)
    elsif arg.arity > 0
      instance_exec(*args.take(arg.arity), &arg)
    else
      instance_exec(*args, &arg)
    end
  else
    arg
  end
end