Skip to content

Instantly share code, notes, and snippets.

@tibbon
Created April 29, 2013 17:09
Show Gist options
  • Save tibbon/5483076 to your computer and use it in GitHub Desktop.
Save tibbon/5483076 to your computer and use it in GitHub Desktop.
yield inside a method
def test(x, func1, func2)
func1.call(x) do | y |
func2.call(y)
end
end
#change func1 to a method
def func1 x
for i in 1 .. 5
yield x * i
end
end
#func2 may be either a method or a lambda
#I changed it for consistency, but you don't have to
def func2 y
puts y
end
test(2, method(:func1), method(:func2))
@tibbon
Copy link
Author

tibbon commented Apr 29, 2013

Not my code btw. Just copypasta'd from a Stack Overflow example to share with a friend.

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