Created
July 31, 2014 23:39
-
-
Save hannestyden/7bc50765b74976a4b5a0 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 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