- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.rb
More file actions
Latest commit
41 lines (39 loc) · 866 Bytes
/
Copy pathdebug.rb
File metadata and controls
41 lines (39 loc) · 866 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
# 19/08/10
moduleDebug
# Log to a file either a) the value of some variables at the point of
# invocation or b) a message.
#
# The variables are passed inside a block as an array of symbols.
defDebug.debug(opts={}, &blk)
msg=[]
ifopts.include?:msg
msg << "#{opts[:msg]}"
end
ifblock_given?
(yield.map &:to_s).eachdo |var|
val=evalvar,blk.binding
msg << "#{var} = #{val}"
end
end
unlessmsg.empty?
msg.unshiftcaller.last.to_s
log=opts[:log] || "debug.log"
File.openlog,"a"do |log|
log.writemsg.join("\n")
log.write"\n\n"
end
end
end
end
if__FILE__ == $0
x=1
y=2
Debug.debug{[:x,:y]}
z=3
Debug.debug{[:x,:y,:z]}
Debug.debugmsg: "Test"
Debug.debug
Debug.debugmsg: "Test 2"do
[:x,:y]
end
end