You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
358 B

13 years ago
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." }
def repeat(n)
if block_given?
n.times { yield }
else
raise ArgumentError.new("I can't repeat a block you don't give me!")
end
end
repeat(4) { puts "Hello." }
repeat(4)