-
-
Save jjb/3471092 to your computer and use it in GitHub Desktop.
method which accepts multiple blocks
This file contains hidden or 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 generate_continue_object(*args) | |
args.each{|a| puts a.inspect} | |
yield if block_given? | |
continue_object = Object.new | |
def continue_object.next_block | |
if block_given? | |
yield | |
generate_continue_object | |
end | |
end | |
continue_object | |
end | |
generate_continue_object(1,2,3) do | |
puts "1/1" | |
end | |
generate_continue_object(:a, "hi") do | |
puts "1/3" | |
end.next_block do | |
puts "2/3" | |
end.next_block do | |
puts "3/3" | |
end |
This file contains hidden or 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
output: | |
1 | |
2 | |
3 | |
1/1 | |
:a | |
"hi" | |
1/3 | |
2/3 | |
3/3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment