-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ex14.rb
49 lines (44 loc) · 769 Bytes
/
Ex14.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
38
39
40
41
42
43
44
45
46
47
48
49
# Even better profiling
=begin
def profile block_description, &block
switch = false
if switch
start_time = Time.new
block.call
duration = Time.new - start_time
puts "#{block_description}: #{duration} seconds"
else
block.call
end
end
profile 'count to a million' do
number = 0
1000000.times do
number = number + 1
end
end
# Grandfather clock
def grandfather_clock &dong
chime = Time.new.hour
chime.times do
dong.call
end
end
grandfather_clock do
puts 'Dong'
end
=end
# Program logger
def log block_des, &block
a = block.call
puts "#{block_des} has started..."
puts "#{block_des} has ended!"
puts "It returned: #{a}"
end
log 'not much' do
log 'something' do
puts 'monkey'
2+2
end
6**32
end