Module: Lab42::Function::MakeFunction

Extended by:
MakeFunction
Included in:
MakeFunction
Defined in:
lib/lab42/function/make_function.rb

Instance Method Summary collapse

Instance Method Details

#make_function(from) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/lab42/function/make_function.rb', line 5

def make_function from
  case from
  when Symbol
    Lab42::Function.free_receiver from
  when Array
    make_function_from_ary from
  when Proc, Method
    Lab42::Function.new from, from.arity
  when Lab42::Function
    from
  else
    raise ArgumentError, "cannot make a behavior from #{from.inspect}"
  end
end

#make_function_from_ary(ary) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/lab42/function/make_function.rb', line 20

def make_function_from_ary ary
  case ary.first
  when Symbol
    Lab42::Function.free_receiver( *ary )
  else
    Lab42::Function.partial( *ary )
  end
end