Skip to content

Instantly share code, notes, and snippets.

@orend
Created September 10, 2012 15:10
Show Gist options
  • Save orend/3691396 to your computer and use it in GitHub Desktop.
Save orend/3691396 to your computer and use it in GitHub Desktop.
&method
[1,2,3].each(&method(:puts)) # & creates a block from a proc, Method has a to_proc method. This is a shortcut for [1,2,3].each(&method(:puts).to_proc)
[1, 2, 3].map(&2.method(:*))
# => [2, 4, 6]
p = method(:puts)
[1,2,3].tap(&p).inject(&:+) # if you need to print something in the middle of a call chain
#something else:
>> (1..10).zip(11..20).map{|x, y| x+y}
[
[0] 12,
[1] 14,
[2] 16,
[3] 18,
[4] 20,
[5] 22,
[6] 24,
[7] 26,
[8] 28,
[9] 30
]
-------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment