Skip to content

Instantly share code, notes, and snippets.

@benolee
Last active December 24, 2015 02:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benolee/6732954 to your computer and use it in GitHub Desktop.
Save benolee/6732954 to your computer and use it in GitHub Desktop.
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