29 lines
487 B
Ruby
29 lines
487 B
Ruby
# WRONG
|
|
# aBlock = { |x| puts x }
|
|
|
|
# RIGHT
|
|
aBlock = lambda { |x| puts x }
|
|
|
|
aBlock.call "Hello World!"
|
|
|
|
|
|
def my_lambda(&aBlock)
|
|
aBlock
|
|
end
|
|
|
|
b = my_lambda { puts "Hello World My Way!" }
|
|
b.call
|
|
|
|
aBlock = Proc.new { |x| puts x }
|
|
aBlock = proc { |x| puts x }
|
|
aBlock = lambda { |x| puts x }
|
|
|
|
add_lambda = lambda { |x,y| x + y }
|
|
# add_lambda.call(4)
|
|
# add_lambda.call(4,5,6)
|
|
puts add_lambda.call(4,2)
|
|
|
|
add_procnew = Proc.new { |x,y| x + y }
|
|
# add_procnew.call(4)
|
|
puts add_procnew.call(4,5,6)
|