Skip to content

Instantly share code, notes, and snippets.

@bfabry
Created March 17, 2012 03:03
Show Gist options
  • Save bfabry/2054612 to your computer and use it in GitHub Desktop.
Save bfabry/2054612 to your computer and use it in GitHub Desktop.
using inject to imitate method chaining with a right-fold
s = "blah blah blah"
ops = {:split => " ", :first => 2}
ops.to_a.reverse.inject(lambda {|x| x}) {|memo,(k,v)| lambda {|x| memo.call(x.send(k,v)) } }.call(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment