Created
February 12, 2015 10:39
-
-
Save aoitaku/507d3da3a73254be9d46 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Symbol | |
def call(*args, &block) | |
if block | |
-> recv { to_proc.(recv, *args, &block) } | |
else | |
-> recv { to_proc.(recv, *args) } | |
end | |
end | |
end | |
class Array | |
def call(*args, &block) | |
symbol, * = *self | |
if block | |
-> recv { symbol.to_proc.(recv, *args, &block) } | |
else | |
-> recv { symbol.to_proc.(recv, *args) } | |
end | |
end | |
def to_proc | |
-> callables { | |
-> recv { | |
callables.inject(recv) {|r, c| c.call(r) } | |
} | |
}.(self.map {|_| symbol, *args = *_.first ; symbol.(*args) }) | |
end | |
end | |
class Hash | |
def call(*args, &block) | |
symbol, * = *self.first | |
if block | |
-> recv { symbol.to_proc.(recv, *args, &block) } | |
else | |
-> recv { symbol.to_proc.(recv, *args) } | |
end | |
end | |
def to_proc | |
-> callables { | |
-> recv { | |
callables.inject(recv) {|r, c| c === r } | |
} | |
}.([*self].map {|symbol, *args| symbol.(*args) }) | |
end | |
end | |
p [*0..10].map(&:*.(2)) | |
p [*0..10].map(&{:* => 2, :+ => 3}) | |
p [*0..10].map(&[{:* => 3}, {:/ => 2}, {:+ => 1}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment