Writing a Method that Accepts a Block
def call_twice
puts "I'm about to call your block."
yield
puts "I'm about to call your block again."
yield
end
call_twice { puts "Hi, I'm a talking code block." }
# I'm about to call your block.
# Hi, I'm a talking code block.
# I'm about to call your block again.
# Hi, I'm a talking code block.
Related examples in the same category