Created
November 28, 2014 13:20
-
-
Save ohthatjames/de7a516ac13d0da2147e to your computer and use it in GitHub Desktop.
Don't monkeypatch symbol for to_proc!
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
require 'blankslate' | |
class Functioniser < BlankSlate | |
class Func | |
def initialize(method) | |
@method = method | |
end | |
def to_proc | |
->(x, *args) { x.send(@method, *args)} | |
end | |
end | |
def method_missing(method) | |
Func.new(method) | |
end | |
end | |
# Not sure if it's safe to use $_, or if it's used for something else... | |
$_ = Functioniser.new | |
puts [1,2,3].map(&$_.to_s).inspect | |
# => ["1", "2", "3"] | |
puts [1,2,3].inject(&$_.+).inspect | |
# => 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment