pretty_inspect 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pretty_inspect.rb +31 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cddc31b7364e0b982cde02b7293773967a3f526
|
4
|
+
data.tar.gz: 37e39a71b5d19900d50bf9f43d8426b8752eab82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 283331798f4e0b2c9c9c430b917cc36a0c560a3307573d825535280d1f9b54b973cba0ee113c318029579fc92b16edd3882d389b90f1388b1a41b14126666382
|
7
|
+
data.tar.gz: 61d5684e4360ed11234ee8823e5429d6d843711e8397087feaafbfdab4b894a43877c840c644b40660ba440332a1544c6fa2db3d8b53bb2967a76167895e596a
|
data/lib/pretty_inspect.rb
CHANGED
@@ -21,9 +21,9 @@ class Object
|
|
21
21
|
# "a",
|
22
22
|
# "b",
|
23
23
|
# {
|
24
|
-
# 1
|
25
|
-
# 2
|
26
|
-
# @y
|
24
|
+
# 1="a",
|
25
|
+
# 2=<X
|
26
|
+
# @y=7
|
27
27
|
# >
|
28
28
|
# },
|
29
29
|
# "c"
|
@@ -32,19 +32,26 @@ class Object
|
|
32
32
|
# irb>
|
33
33
|
|
34
34
|
def pretty_inspect
|
35
|
-
|
35
|
+
object_ids = []
|
36
|
+
pretty_inspect_core("", self, 0, "", object_ids)
|
36
37
|
end
|
37
38
|
|
38
39
|
private
|
39
40
|
|
40
|
-
def pretty_inspect_core(values, level, output)
|
41
|
+
def pretty_inspect_core(name, values, level, output, object_ids)
|
41
42
|
case values
|
42
43
|
when Array
|
43
44
|
output << "[\n"
|
44
45
|
count = values.size
|
45
46
|
values.each do |value|
|
46
47
|
output << " "*(level+2)
|
47
|
-
|
48
|
+
if object_ids.index(value.object_id)
|
49
|
+
output << "[%s ...]"%name
|
50
|
+
else
|
51
|
+
object_ids.push(value.object_id)
|
52
|
+
pretty_inspect_core(name, value,level+2,output,object_ids)
|
53
|
+
object_ids.pop
|
54
|
+
end
|
48
55
|
output << (if (count -= 1) > 0 then ",\n" else "\n" end)
|
49
56
|
end
|
50
57
|
output << "%s]"%(" "*level)
|
@@ -52,8 +59,14 @@ private
|
|
52
59
|
output << "{\n"
|
53
60
|
count = values.size
|
54
61
|
values.each do |key,value|
|
55
|
-
output << "%s%s
|
56
|
-
|
62
|
+
output << "%s%s=>"%[" "*(level+2),key.inspect]
|
63
|
+
if object_ids.index(value.object_id)
|
64
|
+
output << "{@%s ...}"%key
|
65
|
+
else
|
66
|
+
object_ids.push(value.object_id)
|
67
|
+
pretty_inspect_core(key, value,level+2,output,object_ids)
|
68
|
+
object_ids.pop
|
69
|
+
end
|
57
70
|
output << (if (count -= 1) > 0 then ",\n" else "\n" end)
|
58
71
|
end
|
59
72
|
output << "%s}"%(" "*level)
|
@@ -62,16 +75,22 @@ private
|
|
62
75
|
if count==0
|
63
76
|
output << values.inspect
|
64
77
|
else
|
65
|
-
output << "<%s\n"%values.class.name
|
78
|
+
output << "<%s:%d\n"%[values.class.name,values.object_id]
|
66
79
|
values.instance_variables.each do |item|
|
67
80
|
value = values.instance_variable_get(item)
|
68
81
|
output << " "*(level+2)
|
69
82
|
case value
|
70
83
|
when Bignum,Complex,FalseClass,Fixnum,Float,Integer,NilClass,Numeric,Regexp,String,TrueClass
|
71
|
-
output << "%s
|
84
|
+
output << "%s=%s"%[item,value.inspect]
|
72
85
|
else
|
73
|
-
output << "%s
|
74
|
-
|
86
|
+
output << "%s="%item
|
87
|
+
if object_ids.index(value.object_id)
|
88
|
+
output << "<%s ...>"%item
|
89
|
+
else
|
90
|
+
object_ids.push(value.object_id)
|
91
|
+
pretty_inspect_core(item,value,level+2,output,object_ids)
|
92
|
+
object_ids.pop
|
93
|
+
end
|
75
94
|
end
|
76
95
|
output << (if (count -= 1) > 0 then ",\n" else "\n" end)
|
77
96
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pretty_inspect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael J. Welch, Ph.D.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Pretty Inspect can be used anywhere Object::inspect can be used, and
|
14
14
|
produces a more human readable representation of the object.
|