Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created January 29, 2016 08:50
Show Gist options
  • Save Integralist/8079e79c5eb4e7b88183 to your computer and use it in GitHub Desktop.
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
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