-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14.4.program.logger.rb
More file actions
33 lines (29 loc) · 916 Bytes
/
14.4.program.logger.rb
File metadata and controls
33 lines (29 loc) · 916 Bytes
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
# Write a method called log that takes a string description of a block,
# and a block.
# It should tell you it started the block and tell you it finished
# while also telling what the block returned.
# Test it by sending it a code blockk and inside the block put another
# call to log passing a block into it.
# Example output
# 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!
# ..."out block" finished, returning: false
def log block_description, &block
puts "Beginning #{block_description}..."
result = block.call
puts "...#{block_description} finished, returning: #{result.to_s}"
end
log 'outer block' do
log 'some little block' do
5 * 5
end
log 'yet another block' do
output = 'I like Thai Food!'
end
output = false
end