Skip to content

Instantly share code, notes, and snippets.

@staszek
Created September 30, 2011 17:14
Show Gist options
  • Select an option

  • Save staszek/1254388 to your computer and use it in GitHub Desktop.

Select an option

Save staszek/1254388 to your computer and use it in GitHub Desktop.
Chain map,each, select etc.
class Array
def to_proc
proc do |obj, *args|
self.inject(obj) do |result, element|
result = result.send(element, *args)
end
end
end
end
ree-1.8.7-2010.02 > ["john", "alice", "ben"].map(&[:reverse, :capitalize, :reverse])
=> ["johN", "alicE", "beN"]
@staszek
Copy link
Author

staszek commented Sep 30, 2011

result = result.send(element, *args)

could be

result.send(element, *args)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment