pretty_inspect 1.1.0 → 1.2.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 +70 -52
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6771506678b3477cfad87b774a2e95c9887933e2
|
4
|
+
data.tar.gz: 62e886dbda283df155e841f6b086d2ca1e0cc372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d207342a2dbca645fafc7bccaab54f136a59704286fd23eb0b7de45632100720f9d64d64ca1e7ceea918d329928a77f2cb6c5cc956daa432225007042a2c89fc
|
7
|
+
data.tar.gz: 4b942186cb96a949398538d81f8d839bc1e94823d6b3b833e801cd053dd9b1120e5b6f6fda409775761dde19851d4cba48cee522e9fa95b0db2dd27a3b7a1d23
|
data/lib/pretty_inspect.rb
CHANGED
@@ -31,7 +31,8 @@ class Object
|
|
31
31
|
# => nil
|
32
32
|
# irb>
|
33
33
|
|
34
|
-
def pretty_inspect
|
34
|
+
def pretty_inspect(max_level=999)
|
35
|
+
@max_level = (max_level-1)
|
35
36
|
object_ids = []
|
36
37
|
pretty_inspect_core("", self, 0, "", object_ids)
|
37
38
|
end
|
@@ -39,65 +40,82 @@ class Object
|
|
39
40
|
private
|
40
41
|
|
41
42
|
def pretty_inspect_core(name, values, level, output, object_ids)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
if object_ids.index(value.object_id)
|
49
|
-
output << "[%s ...]"%name
|
43
|
+
case values
|
44
|
+
when Array
|
45
|
+
output << "[\n"
|
46
|
+
if (level>>1) > @max_level
|
47
|
+
output << " "*(level+2)
|
48
|
+
output << "et.al.\n"
|
50
49
|
else
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
count = values.size
|
51
|
+
values.each do |value|
|
52
|
+
output << " "*(level+2)
|
53
|
+
if object_ids.index(value.object_id)
|
54
|
+
output << "[%s ...]"%name
|
55
|
+
else
|
56
|
+
object_ids.push(value.object_id)
|
57
|
+
pretty_inspect_core(name, value,level+2,output,object_ids)
|
58
|
+
object_ids.pop
|
59
|
+
end
|
60
|
+
output << (if (count -= 1) > 0 then ",\n" else "\n" end)
|
61
|
+
end
|
54
62
|
end
|
55
|
-
output <<
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
output << "%s%s=>"%[" "*(level+2),key.inspect]
|
63
|
-
if object_ids.index(value.object_id)
|
64
|
-
output << "{@%s ...}"%key
|
63
|
+
output << " "*level
|
64
|
+
output << "]"
|
65
|
+
when Hash
|
66
|
+
output << "{\n"
|
67
|
+
if (level>>1) > @max_level
|
68
|
+
output << " "*(level+2)
|
69
|
+
output << "et.al.\n"
|
65
70
|
else
|
66
|
-
|
67
|
-
|
68
|
-
|
71
|
+
count = values.size
|
72
|
+
values.each do |key,value|
|
73
|
+
output << "%s%s=>"%[" "*(level+2),key.inspect]
|
74
|
+
if object_ids.index(value.object_id)
|
75
|
+
output << "{@%s ...}"%key
|
76
|
+
else
|
77
|
+
object_ids.push(value.object_id)
|
78
|
+
pretty_inspect_core(key, value,level+2,output,object_ids)
|
79
|
+
object_ids.pop
|
80
|
+
end
|
81
|
+
output << (if (count -= 1) > 0 then ",\n" else "\n" end)
|
82
|
+
end
|
69
83
|
end
|
70
|
-
output <<
|
71
|
-
|
72
|
-
output << "%s}"%(" "*level)
|
73
|
-
else
|
74
|
-
count = values.instance_variables.count
|
75
|
-
if count==0
|
76
|
-
output << values.inspect
|
84
|
+
output << " "*level
|
85
|
+
output << "}"
|
77
86
|
else
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
87
|
+
count = values.instance_variables.count
|
88
|
+
if count==0
|
89
|
+
output << values.inspect
|
90
|
+
else
|
91
|
+
output << "<%s:%d\n"%[values.class.name,values.object_id]
|
92
|
+
if (level>>1) > @max_level
|
93
|
+
output << " "*(level+2)
|
94
|
+
output << "et.al.\n"
|
95
|
+
else
|
96
|
+
values.instance_variables.each do |item|
|
97
|
+
value = values.instance_variable_get(item)
|
98
|
+
output << " "*(level+2)
|
99
|
+
case value
|
100
|
+
when Bignum,Complex,FalseClass,Fixnum,Float,Integer,NilClass,Numeric,Regexp,String,TrueClass
|
101
|
+
output << "%s=%s"%[item,value.inspect]
|
102
|
+
else
|
103
|
+
output << "%s="%item
|
104
|
+
if object_ids.index(value.object_id)
|
105
|
+
output << "<%s ...>"%item
|
106
|
+
else
|
107
|
+
object_ids.push(value.object_id)
|
108
|
+
pretty_inspect_core(item,value,level+2,output,object_ids)
|
109
|
+
object_ids.pop
|
110
|
+
end
|
93
111
|
end
|
112
|
+
output << (if (count -= 1) > 0 then ",\n" else "\n" end)
|
113
|
+
end
|
94
114
|
end
|
95
|
-
|
115
|
+
output << " "*level
|
116
|
+
output << ">"
|
96
117
|
end
|
97
|
-
|
98
|
-
end
|
99
|
-
end
|
118
|
+
end
|
100
119
|
end
|
101
120
|
|
102
121
|
end
|
103
|
-
|
metadata
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pretty_inspect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.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-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
produces a more human readable representation of the object.
|
13
|
+
description: |-
|
14
|
+
Pretty Inspect can be used anywhere Object::inspect can be used, and produces a more human readable representation of the object.
|
15
|
+
|
16
|
+
Can be called as object.pretty_inspect, or object.pretty_inspect(n) where n is the maximum depth to display.
|
15
17
|
email: rubygems@czarmail.com
|
16
18
|
executables: []
|
17
19
|
extensions: []
|