Is block ready : block_given « Method « Ruby
- Ruby
- Method
- block_given
Is block ready
#!/usr/bin/env ruby
def gimme
if block_given?
yield
else
puts "Oops. No block."
end
puts "You're welcome." # executes right after yield
end
gimme { print "Thank you. " } # => Thank you. You're welcome.
Related examples in the same category