Skip to content

Instantly share code, notes, and snippets.

@hannestyden
Created July 31, 2014 23:39
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 hannestyden/7bc50765b74976a4b5a0 to your computer and use it in GitHub Desktop.
Save hannestyden/7bc50765b74976a4b5a0 to your computer and use it in GitHub Desktop.
def scream(s)
s.upcase
end
array = %w[i scream u scream we all scream for icecream]
## "On" the object
array.map(&:upcase)
# => ["I", "SCREAM", "U", "SCREAM", "WE", "ALL", "SCREAM", "FOR", "ICECREAM"]
array.map { |c| c.method(:upcase).call }
# => ["I", "SCREAM", "U", "SCREAM", "WE", "ALL", "SCREAM", "FOR", "ICECREAM"]
## Passes the object
array.map(&method(:scream))
# => ["I", "SCREAM", "U", "SCREAM", "WE", "ALL", "SCREAM", "FOR", "ICECREAM"]
array.map { |c| method(:scream).call(c) }
# => ["I", "SCREAM", "U", "SCREAM", "WE", "ALL", "SCREAM", "FOR", "ICECREAM"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment