Skip to content

Instantly share code, notes, and snippets.

@holysugar
Last active October 30, 2017 07:33
Show Gist options
  • Save holysugar/3400fd679723982ec1e681000ef3ce7d to your computer and use it in GitHub Desktop.
Save holysugar/3400fd679723982ec1e681000ef3ce7d to your computer and use it in GitHub Desktop.
to_proc
class Array
def to_proc
->(this) { this.send(*self) }
end
end
[1,2,3].map(&[:+, 1]) #=> [2,3,4]
def apply(sym, args=[]); ->(this) { this.send(sym, *args) }; end
alias _ apply
[1,2,3].map(&_(:+, 1)) #=> [2,3,4]
class Symbol
def [](*args)
->(this) { this.send(self, *args) }
end
end
[1,2,3].map(&:+[1]) #=> [2,3,4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment