Skip to content

Instantly share code, notes, and snippets.

@certainty
Created September 27, 2012 07:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save certainty/3792694 to your computer and use it in GitHub Desktop.
Save certainty/3792694 to your computer and use it in GitHub Desktop.
generalized method chaining and array as applicative
class Array
def >>(other); self + [other]; end
def to_proc(*args)
->(r) { inject(r){ |o,(m,*args)| o.send(m,*args) } }
end
def apply(rec)
self.to_proc[rec]
end
end
class Symbol
def >>(other); [self,other] end
end
puts %w(foo bar baz).map(&:upcase >> :reverse)
puts (1..9).map(&[[:+,3],[:-,2]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment