Proc&Lamda
Proc
cube = Proc.new{ |x| x ** 3 }[1, 2, 3].collect!(&cube)
# ==> [1, 8, 27]
[4, 5, 6].map!(&cube)
# ==> [64, 125, 216]test = Proc.new { # does something }
test.call
# does that something!strings = ["1", "2", "3"]
nums = strings.map(&:to_i)
# ==> [1, 2, 3]Lambda
proc과 lambda의 차이
Scope
Last updated