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.
15 lines
353 B
15 lines
353 B
def call_twice
|
|
puts "Calling your block."
|
|
ret1 = yield("very first")
|
|
puts "The value of your block: #{ret1}"
|
|
|
|
puts "Calling your block again."
|
|
ret2 = yield("second")
|
|
puts "The value of your block: #{ret2}"
|
|
end
|
|
|
|
call_twice do |which_time|
|
|
puts "I'm a code block, called for the #{which_time} time."
|
|
which_time == "very first" ? 1 : 2
|
|
end
|