Skip to content

Instantly share code, notes, and snippets.

@fronx
Created September 20, 2012 11:52
Show Gist options
  • Select an option

  • Save fronx/3755468 to your computer and use it in GitHub Desktop.

Select an option

Save fronx/3755468 to your computer and use it in GitHub Desktop.
point-free block passing in ruby
"abcd".method(:length).to_proc.call
# => 4
# ---
def a(x,y)
[x, y]
end
def b
yield(1, 2)
end
# explicit points:
b { |x, y| a(x, y) }
# => [1, 2]
b { |*args| a(*args) }
# => [1, 2]
# point-free:
b(&method(:a))
# => [1, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment