display 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/display.rb +17 -10
- data/spec/spec.display.rb +15 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/display.rb
CHANGED
@@ -14,18 +14,25 @@ class Object
|
|
14
14
|
file, line, *rest = last_caller.split(":")
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
if(file.include?('eval'))
|
18
|
+
out = '[eval] '
|
19
|
+
names = args.map{|a| '?'}
|
20
|
+
else
|
21
|
+
exact_line = File.readlines(file)[line.to_i - 1].strip
|
22
|
+
parser = RedParse.new(exact_line)
|
23
|
+
tree = parser.parse
|
24
|
+
# the trick is to break out with the first method call...
|
25
|
+
right_call_node = give_me_first_call_node tree
|
26
|
+
names = right_call_node.params.map{|p| p.unparse}
|
27
|
+
out = "[#{File.basename(file)},#{line}] "
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
args2 = names.map{ |n|
|
32
|
+
"#{n}=#{args.shift.inspect}"
|
26
33
|
}.join(', ')
|
27
|
-
out += args2
|
28
34
|
|
35
|
+
out += args2
|
29
36
|
puts out
|
30
37
|
out
|
31
38
|
end
|
data/spec/spec.display.rb
CHANGED
@@ -47,5 +47,20 @@ describe "display" do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should cache lines instead of rereading the file each time"
|
50
|
+
|
51
|
+
it "should use inspect" do
|
52
|
+
a = [1,2,3]
|
53
|
+
out = display a
|
54
|
+
assert out.contain? "[1, 2, 3]"
|
55
|
+
out = display [1,2,3]
|
56
|
+
assert out.contain? "[1, 2, 3]"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should pretend to work in eval" do
|
60
|
+
out = eval("display 1,2,3")
|
61
|
+
assert(out.contain?('?='))
|
62
|
+
assert(out.contain?('eval'))
|
63
|
+
assert(out.contain?('1'))
|
64
|
+
end
|
50
65
|
|
51
66
|
end
|