pretty_inspect 0.9.0 → 1.0.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 +37 -7
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a948fef234fb447640b003c2e791d48e09a2ad68
4
- data.tar.gz: a01b4aff91843ae8d5eca50e5c58667db91d6ea8
3
+ metadata.gz: 7b7371ec261daafaca842ace53bf03417c651395
4
+ data.tar.gz: 5aac3d4bec3ab74912b217a3303b5d95e6427fa2
5
5
  SHA512:
6
- metadata.gz: 3bca9842c58adfe5aecb48665808c67512eee07f60993dc70f053a50fad1be4f1cc9094294157baaf5812975b92c1b913cb319612576c903ad416e646d85a75a
7
- data.tar.gz: d5a9f54be9e0f1a3b50c95d210314843c4cd6b6b7671e283c1ba82acc3ad1bff107c09f94e34a21837c5be1459eb8658824632673fc3f1d2e7b62c894e578232
6
+ metadata.gz: 1f832e904986c14d59718b67096020dbe5d41d0934acd35a6809771def19f10aa54cad3a369fe586b8a2875b63b00a4da48370b321874ca282b3058a40c776f9
7
+ data.tar.gz: aea8700802266ba20babfe72a2539d93b0cd5b86e3be563a90eb23e2a1716948cd66ee764c83895900ab2a6121623609986f121cda883f5e40873846c7928349
@@ -10,19 +10,33 @@ class Object
10
10
  # Example:
11
11
  # irb> require 'pretty_inspect'
12
12
  # => true
13
- # irb> puts (['a','b',{1=>'a',2=>'b'},'c'].pretty_inspect)
13
+ # irb> class X
14
+ # irb> def initialize
15
+ # irb> @y = 7
16
+ # irb> end
17
+ # irb> end
18
+ # => nil
19
+ # irb> puts (['a','b',{1=>'a',2=>X.new},'c'].pretty_inspect)
14
20
  # [
15
21
  # "a",
16
22
  # "b",
17
23
  # {
18
24
  # 1 => "a",
19
- # 2 => "b"
25
+ # 2 => <X
26
+ # @y => 7
27
+ # >
20
28
  # },
21
29
  # "c"
22
30
  # ]
23
31
  # => nil
24
32
  # irb>
25
33
 
34
+ def pretty_inspect
35
+ pretty_inspect_core(self, 0, "")
36
+ end
37
+
38
+ private
39
+
26
40
  def pretty_inspect_core(values, level, output)
27
41
  case values
28
42
  when Array
@@ -44,11 +58,27 @@ class Object
44
58
  end
45
59
  output << "%s}"%(" "*level)
46
60
  else
47
- output << values.inspect
61
+ count = values.instance_variables.count
62
+ if count==0
63
+ output << values.inspect
64
+ else
65
+ output << "<%s\n"%values.class.name
66
+ values.instance_variables.each do |item|
67
+ value = values.instance_variable_get(item)
68
+ output << " "*(level+2)
69
+ case value
70
+ when Bignum,Complex,FalseClass,Fixnum,Float,Integer,NilClass,Numeric,Regexp,String,TrueClass
71
+ output << "%s => %s"%[item,value.inspect]
72
+ else
73
+ output << "%s => "%item
74
+ pretty_inspect_core(value,level+2,output)
75
+ end
76
+ output << (if (count -= 1) > 0 then ",\n" else "\n" end)
77
+ end
78
+ output << "%s>"%(" "*level)
79
+ end
48
80
  end
49
81
  end
50
-
51
- def pretty_inspect
52
- pretty_inspect_core(self, 0, "")
53
- end
82
+
54
83
  end
84
+
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: 0.9.0
4
+ version: 1.0.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-04-18 00:00:00.000000000 Z
11
+ date: 2014-07-23 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.
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  version: '0'
39
39
  requirements: []
40
40
  rubyforge_project:
41
- rubygems_version: 2.0.7
41
+ rubygems_version: 2.2.2
42
42
  signing_key:
43
43
  specification_version: 4
44
44
  summary: Pretty Inspect (pretty_inspect) is an extension to Object::inspect.