Skip to content

Instantly share code, notes, and snippets.

@haru01
Created June 2, 2010 12:36
Show Gist options
  • Save haru01/422313 to your computer and use it in GitHub Desktop.
Save haru01/422313 to your computer and use it in GitHub Desktop.
class Array
def maps(*methods)
methods = [methods].flatten
self.map do |node|
methods.inject(node) {|result, method| method.call(result) }
end
end
end
twice = lambda {|node| node * 2 }
triple = lambda {|node| node * 3 }
plus1 = lambda {|node| node + 1 }
puts (1..10).to_a.maps([plus1, triple, twice])
puts (1..10).to_a.maps(plus1, plus1, twice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment