Created
April 29, 2013 17:09
-
-
Save tibbon/5483076 to your computer and use it in GitHub Desktop.
yield inside a method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not my code btw. Just copypasta'd from a Stack Overflow example to share with a friend.