Skip to content

Instantly share code, notes, and snippets.

@jhamon
Last active December 23, 2015 12:09
Show Gist options
  • Save jhamon/6633713 to your computer and use it in GitHub Desktop.
Save jhamon/6633713 to your computer and use it in GitHub Desktop.
def mymethod(&blk) #Expects a block argument
puts "Hello from inside mymethod."
puts "Your block returns #{blk.call}"
end
mymethod do
puts "Hello from a block."
puts "I was to_proc'd and then called like a proc object."
end
# Results:
# Hello from inside mymethod.
# Hello from a block.
# I was to_proc'd and then called like a proc object.
# Your block returns
# => nil
#
# The &parameter syntax in the method definition is
# syntactic sugar that allows us to accept blocks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment