box-o-sand/cookbook/007/01.rb

29 lines
487 B
Ruby
Raw Normal View History

2011-10-07 02:03:01 +00:00
# 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)