Last active
October 30, 2017 07:33
-
-
Save holysugar/3400fd679723982ec1e681000ef3ce7d to your computer and use it in GitHub Desktop.
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
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