-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloggers.rb
More file actions
50 lines (37 loc) · 912 Bytes
/
loggers.rb
File metadata and controls
50 lines (37 loc) · 912 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def log block_description, &block
puts 'Beginning "'+block_description+'" . . .'
value_returned = block.call
puts '. . . "'+block_description+'" finished, returning:'
puts value_returned
end
log 'outer block' do
log 'some little block' do
5
end
log 'yet another block' do
'I like Thai food!'
end
false
end
$depth = 0
$space = ' '
def better_log description, &block
puts $space*$nesting_depth + 'Beginning "'+block_description+'" ...'
$nesting_depth = $nesting_depth + 1
value_returned = block.call
$nesting_depth = $nesting_depth - 1
puts $space*$nesting_depth + '... "'+block_description+'" finished, returning:'
puts $space*$nesting_depth + value_returned.to_s
end
log 'outer block' do
log 'some little block' do
log 'teeny-tiny block' do
'lots of love'
end
42
end
log 'yet another block' do
'I love Indian food!'
end
true
end