Skip to content

Instantly share code, notes, and snippets.

@blowmage
Created December 14, 2011 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blowmage/1475026 to your computer and use it in GitHub Desktop.
Save blowmage/1475026 to your computer and use it in GitHub Desktop.
Blocks, Procs and Lambda - Oh My!
def test_lambda
puts "About to call lambda"
blck = lambda do
puts " -- Start lambda"
return "lambda"
puts " -- End lambda"
end
val = blck.call
puts "The value is #{val}"
puts "Just called lambda"
end
test_lambda
def test_proc
puts "About to call proc"
blck = proc do
puts " -- Start proc"
return "proc"
puts " -- End proc"
end
val = blck.call
puts "The value is #{val}"
puts "Just called proc"
end
test_proc
def test_proc_object
puts "About to call Proc.new"
blck = Proc.new do
puts " -- Start Proc.new"
return "Proc.new"
puts " -- End Proc.new"
end
val = blck.call
puts "The value is #{val}"
puts "Just called Proc.new"
end
test_proc_object
# Try running on Ruby 1.8.7 and 1.9.3
puts "Blocks, Procs and Lambdas, Oh My!\n\n"
require "lambda"
puts "\n\n"
require "proc"
puts "\n\n"
require "proc_object"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment