Module: Ick::LetnLambda

Included in:
Cletn, Letn
Defined in:
lib/ick/letn.rb

Instance Method Summary collapse

Instance Method Details

#letn_lambda(names_to_values, proc) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/ick/letn.rb', line 8

def letn_lambda(names_to_values, proc)
  sorted_names = (names_to_values || {}).keys.map { |name| name.to_s }.sort
  letn_body = <<LETN_BODY
lambda { |#{sorted_names.join(', ')}|
  #{proc.to_ruby[/^proc \{(.*)\}$/m, 1]}
}
LETN_BODY
  Kernel.eval(letn_body, proc.binding)
end

#rewritten(names_to_values, proc) ⇒ Object



18
19
20
21
22
23
# File 'lib/ick/letn.rb', line 18

def rewritten(names_to_values, proc)
  sorted_symbols = (names_to_values || {}).keys.map { |name| name.to_s }.sort.map { |name| name.to_sym }
  lambda { |names_to_values|
    letn_lambda(names_to_values, proc).call(*sorted_symbols.map { |sym| names_to_values[sym] })
  }
end