doing 7.2

This commit is contained in:
Dan Buch 2011-10-06 22:13:36 -04:00
parent 584e1eceb2
commit 2194c6637e

21
cookbook/007/02.rb Normal file
View File

@ -0,0 +1,21 @@
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)