Skip to content

Instantly share code, notes, and snippets.

@tomwhoiscontrary
Created March 4, 2013 15:12
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 tomwhoiscontrary/5082896 to your computer and use it in GitHub Desktop.
Save tomwhoiscontrary/5082896 to your computer and use it in GitHub Desktop.
What do you think gets printed as Exhibit F?
#! /usr/bin/ruby
def print_call_and_return(string, &block)
puts string
block.call unless !block
"return"
end
puts "=== exhibit A ==="
print_call_and_return("parameter")
puts "=== exhibit B ==="
a = print_call_and_return("parameter")
puts a
puts "=== exhibit C ==="
puts print_call_and_return("parameter")
puts "=== exhibit D ==="
print_call_and_return("parameter") do
puts "block"
end
puts "=== exhibit E ==="
a = print_call_and_return("parameter") do
puts "block"
end
puts a
puts "=== exhibit F ==="
puts print_call_and_return("parameter") do
puts "block"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment