-
Notifications
You must be signed in to change notification settings - Fork 0
/
chap_10_b.rb
37 lines (29 loc) · 1.07 KB
/
chap_10_b.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
=begin
Program Logger. Write a method called log, which takes a string description of a
block and, of course, a block. Similar to doSelfImportantly, it should puts a
string telling that it has started the block, and another string at the end
telling you that it has finished the block, and also telling you what the block
returned. Test your method by sending it a code block. Inside the block, put
another call to log, passing another block to it. (This is called nesting.) In
other words, your output should look something like this:
Beginning "outer block"...
Beginning "some little block"...
..."some little block" finished, returning: 5
Beginning "yet another block"...
..."yet another block" finished, returning: I like Thai food!
..."outer block" finished, returning: false
=end
def log description, &block
puts 'Beginning "'+description+'"...'
return_val = block.call
puts '..."'+description+'" finished, returning: ' + return_val.to_s
end
log "outer block" do
log "some little block" do
5
end
log "yet another block" do
"I like Thai food!"
end
false
end