-
-
Save domgetter/86ad84366e6b30da4775 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
["hello", "world", "hahahahaha"].map(&:length) | |
#=> [5, 5, 10] | |
# So, what's happening is, :length gets #to_proc called on it, which results in map doing the following: | |
["hello", "world", "hahahahaha"].map do |str| | |
:length.to_proc.call(str) | |
end | |
# Now, :length.to_proc.call(str) does the following: | |
str = "hello" | |
str.send(:length) | |
#=> 5 | |
# try it yourself! | |
:+.to_proc.call(2, 3) == 2.send(:+, 3) | |
#=> true | |
# str.send(:length) is (basically) the same as | |
str.length | |
#=> 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment