Skip to content

Instantly share code, notes, and snippets.

@britishtea
Created October 11, 2014 17:17
Show Gist options
  • Save britishtea/79ffe59b775e13af6f76 to your computer and use it in GitHub Desktop.
Save britishtea/79ffe59b775e13af6f76 to your computer and use it in GitHub Desktop.
Two small extensions to `Symbol`.
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