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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pretty_inspect.rb +31 -12
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b7371ec261daafaca842ace53bf03417c651395
4
- data.tar.gz: 5aac3d4bec3ab74912b217a3303b5d95e6427fa2
3
+ metadata.gz: 4cddc31b7364e0b982cde02b7293773967a3f526
4
+ data.tar.gz: 37e39a71b5d19900d50bf9f43d8426b8752eab82
5
5
  SHA512:
6
- metadata.gz: 1f832e904986c14d59718b67096020dbe5d41d0934acd35a6809771def19f10aa54cad3a369fe586b8a2875b63b00a4da48370b321874ca282b3058a40c776f9
7
- data.tar.gz: aea8700802266ba20babfe72a2539d93b0cd5b86e3be563a90eb23e2a1716948cd66ee764c83895900ab2a6121623609986f121cda883f5e40873846c7928349
6
+ metadata.gz: 283331798f4e0b2c9c9c430b917cc36a0c560a3307573d825535280d1f9b54b973cba0ee113c318029579fc92b16edd3882d389b90f1388b1a41b14126666382
7
+ data.tar.gz: 61d5684e4360ed11234ee8823e5429d6d843711e8397087feaafbfdab4b894a43877c840c644b40660ba440332a1544c6fa2db3d8b53bb2967a76167895e596a
@@ -21,9 +21,9 @@ class Object
21
21
  # "a",
22
22
  # "b",
23
23
  # {
24
- # 1 => "a",
25
- # 2 => <X
26
- # @y => 7
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
- pretty_inspect_core(self, 0, "")
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
- pretty_inspect_core(value,level+2,output)
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 => "%[" "*(level+2),key.inspect]
56
- pretty_inspect_core(value,level+2,output)
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 => %s"%[item,value.inspect]
84
+ output << "%s=%s"%[item,value.inspect]
72
85
  else
73
- output << "%s => "%item
74
- pretty_inspect_core(value,level+2,output)
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.0.0
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-07-23 00:00:00.000000000 Z
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.