Created
January 29, 2016 08:50
-
-
Save Integralist/8079e79c5eb4e7b88183 to your computer and use it in GitHub Desktop.
Example script that uses the `&` trick (typically used to convert an object to a proc; e.g. https://gist.github.com/Integralist/11206577) to convert a method (retrieved using `method()`) to a proc so it can be utilised by another method
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 hello(&block) | |
block.call if block_given? | |
end | |
def world | |
"world" | |
end | |
hello # => nil | |
hello { "world" } # => "world" | |
hello(&method(:world)) # => "world" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment