Skip to content

Instantly share code, notes, and snippets.

@jjb
Created August 25, 2012 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjb/3471092 to your computer and use it in GitHub Desktop.
Save jjb/3471092 to your computer and use it in GitHub Desktop.
method which accepts multiple blocks
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
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