Last active
December 24, 2015 02:49
-
-
Save benolee/6732954 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
module PipeMixin | |
def >>(proc_or_method, *) | |
case proc_or_method | |
when Proc, Method, UnboundMethod | |
proc_or_method.call(self) | |
else | |
super | |
end | |
end | |
end | |
class Object | |
include PipeMixin | |
end | |
class UnboundMethod | |
def call(receiver, *args, &block) | |
bind(receiver).call(*args, &block) | |
end | |
end | |
class Symbol | |
def call(*args, &block) | |
proc { |receiver| receiver.send(self, *args, &block) } | |
end | |
end | |
__END__ | |
repl> :abc >> :to_s.() >> :split.(//) >> :join.('_') >> :sub.(/_(.)/, &:upcase) >> :to_sym.() | |
=> :a_B_c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment