Last active
December 23, 2015 12:09
-
-
Save jhamon/6633713 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ¶meter 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