Skip to content

Instantly share code, notes, and snippets.

@bloudermilk
Last active August 29, 2015 13:58
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 bloudermilk/10324323 to your computer and use it in GitHub Desktop.
Save bloudermilk/10324323 to your computer and use it in GitHub Desktop.
Example of yield in ruby
def my_fancy_method
# Call the block with 1
yield 1
# Call the block with "cat"
yield "cat"
# Call the block with nothing (i.e. nil)
yield
end
# Call my_fancy_method and print whatever is passed to the block
my_fancy_method do |lol|
puts lol
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment