pretty_inspect 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pretty_inspect.rb +70 -52
  3. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cddc31b7364e0b982cde02b7293773967a3f526
4
- data.tar.gz: 37e39a71b5d19900d50bf9f43d8426b8752eab82
3
+ metadata.gz: 6771506678b3477cfad87b774a2e95c9887933e2
4
+ data.tar.gz: 62e886dbda283df155e841f6b086d2ca1e0cc372
5
5
  SHA512:
6
- metadata.gz: 283331798f4e0b2c9c9c430b917cc36a0c560a3307573d825535280d1f9b54b973cba0ee113c318029579fc92b16edd3882d389b90f1388b1a41b14126666382
7
- data.tar.gz: 61d5684e4360ed11234ee8823e5429d6d843711e8397087feaafbfdab4b894a43877c840c644b40660ba440332a1544c6fa2db3d8b53bb2967a76167895e596a
6
+ metadata.gz: d207342a2dbca645fafc7bccaab54f136a59704286fd23eb0b7de45632100720f9d64d64ca1e7ceea918d329928a77f2cb6c5cc956daa432225007042a2c89fc
7
+ data.tar.gz: 4b942186cb96a949398538d81f8d839bc1e94823d6b3b833e801cd053dd9b1120e5b6f6fda409775761dde19851d4cba48cee522e9fa95b0db2dd27a3b7a1d23
@@ -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
- case values
43
- when Array
44
- output << "[\n"
45
- count = values.size
46
- values.each do |value|
47
- output << " "*(level+2)
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
- object_ids.push(value.object_id)
52
- pretty_inspect_core(name, value,level+2,output,object_ids)
53
- object_ids.pop
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 << (if (count -= 1) > 0 then ",\n" else "\n" end)
56
- end
57
- output << "%s]"%(" "*level)
58
- when Hash
59
- output << "{\n"
60
- count = values.size
61
- values.each do |key,value|
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
- object_ids.push(value.object_id)
67
- pretty_inspect_core(key, value,level+2,output,object_ids)
68
- object_ids.pop
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 << (if (count -= 1) > 0 then ",\n" else "\n" end)
71
- end
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
- output << "<%s:%d\n"%[values.class.name,values.object_id]
79
- values.instance_variables.each do |item|
80
- value = values.instance_variable_get(item)
81
- output << " "*(level+2)
82
- case value
83
- when Bignum,Complex,FalseClass,Fixnum,Float,Integer,NilClass,Numeric,Regexp,String,TrueClass
84
- output << "%s=%s"%[item,value.inspect]
85
- else
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
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
- output << (if (count -= 1) > 0 then ",\n" else "\n" end)
115
+ output << " "*level
116
+ output << ">"
96
117
  end
97
- output << "%s>"%(" "*level)
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.1.0
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-08-08 00:00:00.000000000 Z
11
+ date: 2014-09-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Pretty Inspect can be used anywhere Object::inspect can be used, and
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: []