Created
October 11, 2014 17:17
-
-
Save britishtea/79ffe59b775e13af6f76 to your computer and use it in GitHub Desktop.
Two small extensions to `Symbol`.
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
class Symbol | |
def [](*args) | |
proc do |object| | |
object.send self, *args | |
end | |
end | |
def ~ | |
proc do |object, *args| | |
object.send self, *args | |
end | |
end | |
end | |
p [1,2,3].map &:+[4] | |
# => [5, 6, 7] | |
p [[1,1],[2,2],[3,3]].map &~:+ | |
# => [2, 4, 6] | |
p [[1,1],[1,2],[3,3]].select &~:== | |
# => [[1,1], [3,3]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment