Skip to content

Instantly share code, notes, and snippets.

@ohthatjames
Created November 28, 2014 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohthatjames/de7a516ac13d0da2147e to your computer and use it in GitHub Desktop.
Save ohthatjames/de7a516ac13d0da2147e to your computer and use it in GitHub Desktop.
Don't monkeypatch symbol for to_proc!
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