pretty_inspect 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/pretty_inspect.rb +48 -40
- metadata +12 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f14bf1dd49884d1751742a03d6e7d68ac8d5948371d8f3e2455af8ad0c1bd0fb
|
4
|
+
data.tar.gz: 0d07fb30a6e750a5309961afdaa1133c592ecb45b3a0f92660366910d4d71cd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 791a9fd6e9c45851914e46ccd6403b634130ee80ff357b817154c0e18be2fedcba44a759af11aab48e5b0a95f1defb28e730abe9f789180b6324009749f375a0
|
7
|
+
data.tar.gz: 7752d84e622abb6a4109f0c027d0a051ba9ff4a891187d28922ec79aaee438f98325ce812fb4489160f3f67aef328f341898d8b1fb584eca3e168315b40745ff
|
data/lib/pretty_inspect.rb
CHANGED
@@ -1,44 +1,51 @@
|
|
1
|
-
# Pretty Inspect
|
1
|
+
# Pretty Inspect Gem
|
2
2
|
|
3
3
|
class Object
|
4
|
-
# This gem extends Object::inspect to "pretty" inspect
|
5
|
-
# arrays and hashes.
|
6
|
-
#
|
7
|
-
# Install:
|
8
|
-
# gem install pretty_inspect
|
9
|
-
#
|
10
|
-
# Example:
|
11
|
-
# irb> require 'pretty_inspect'
|
12
|
-
# => true
|
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)
|
20
|
-
# [
|
21
|
-
# "a",
|
22
|
-
# "b",
|
23
|
-
# {
|
24
|
-
# 1="a",
|
25
|
-
# 2=<X
|
26
|
-
# @y=7
|
27
|
-
# >
|
28
|
-
# },
|
29
|
-
# "c"
|
30
|
-
# ]
|
31
|
-
# => nil
|
32
|
-
# irb>
|
33
4
|
|
34
|
-
|
5
|
+
=begin
|
6
|
+
This gem extends Object::inspect to "pretty" inspect
|
7
|
+
arrays and hashes.
|
8
|
+
|
9
|
+
Example: (copy this to irb)
|
10
|
+
require 'pretty_inspect'
|
11
|
+
require 'bigdecimal'
|
12
|
+
class X
|
13
|
+
def initialize
|
14
|
+
@y = BigDecimal(31.41592653589796,4)
|
15
|
+
@f = false
|
16
|
+
@t = true
|
17
|
+
@g = 3.141592653589796
|
18
|
+
@n = nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
puts (['a','b',{1=>'a',2=>X.new},'c'].pretty_inspect)
|
22
|
+
|
23
|
+
Yields:
|
24
|
+
[
|
25
|
+
"a",
|
26
|
+
"b",
|
27
|
+
{
|
28
|
+
1=>"a",
|
29
|
+
2=><X:47374925831780
|
30
|
+
@f===false,
|
31
|
+
@t===true,
|
32
|
+
@g===3.141592653589796,
|
33
|
+
@n===nil,
|
34
|
+
@y=31.42
|
35
|
+
>
|
36
|
+
},
|
37
|
+
"c"
|
38
|
+
]
|
39
|
+
=end
|
40
|
+
|
41
|
+
def pretty_inspect(max_level=999)
|
35
42
|
object_ids = []
|
36
|
-
pretty_inspect_core("", self, 0, "", object_ids, max_level-1
|
43
|
+
pretty_inspect_core("", self, 0, "", object_ids, max_level-1)
|
37
44
|
end
|
38
45
|
|
39
46
|
private
|
40
47
|
|
41
|
-
def pretty_inspect_core(name, values, level, output, object_ids, max_level
|
48
|
+
def pretty_inspect_core(name, values, level, output, object_ids, max_level)
|
42
49
|
case values
|
43
50
|
when Array
|
44
51
|
output << "[\n"
|
@@ -53,7 +60,7 @@ private
|
|
53
60
|
output << "[%s ...]"%name
|
54
61
|
else
|
55
62
|
object_ids.push(value.object_id)
|
56
|
-
pretty_inspect_core(name, value,level+2,output,object_ids, max_level-1
|
63
|
+
pretty_inspect_core(name, value,level+2,output,object_ids, max_level-1)
|
57
64
|
object_ids.pop
|
58
65
|
end
|
59
66
|
output << (if (count -= 1) > 0 then ",\n" else "\n" end)
|
@@ -74,7 +81,7 @@ private
|
|
74
81
|
output << "{@%s ...}"%key
|
75
82
|
else
|
76
83
|
object_ids.push(value.object_id)
|
77
|
-
pretty_inspect_core(key, value,level+2,output,object_ids, max_level-1
|
84
|
+
pretty_inspect_core(key, value,level+2,output,object_ids, max_level-1)
|
78
85
|
object_ids.pop
|
79
86
|
end
|
80
87
|
output << (if (count -= 1) > 0 then ",\n" else "\n" end)
|
@@ -92,12 +99,13 @@ private
|
|
92
99
|
output << " "*(level+2)
|
93
100
|
output << "et.al.\n"
|
94
101
|
else
|
95
|
-
|
96
|
-
items.each do |item|
|
102
|
+
values.instance_variables.each do |item|
|
97
103
|
value = values.instance_variable_get(item)
|
98
104
|
output << " "*(level+2)
|
99
|
-
case
|
100
|
-
when
|
105
|
+
case
|
106
|
+
when defined?(BigDecimal) && value.class==BigDecimal
|
107
|
+
output << "%s=%s"%[item,value.to_s("F")]
|
108
|
+
when [Complex,FalseClass,Float,Integer,NilClass,Regexp,String,TrueClass].index(value.class)
|
101
109
|
output << "%s=%s"%[item,value.inspect]
|
102
110
|
else
|
103
111
|
output << "%s="%item
|
@@ -105,7 +113,7 @@ private
|
|
105
113
|
output << "<%s ...>"%item
|
106
114
|
else
|
107
115
|
object_ids.push(value.object_id)
|
108
|
-
pretty_inspect_core(item,value,level+2,output,object_ids, max_level-1
|
116
|
+
pretty_inspect_core(item,value,level+2,output,object_ids, max_level-1)
|
109
117
|
object_ids.pop
|
110
118
|
end
|
111
119
|
end
|
metadata
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pretty_inspect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.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:
|
11
|
+
date: 2019-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Pretty Inspect can be used anywhere Object::inspect can be used, and produces a more human readable representation of the object.
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
It can be called as:
|
17
|
+
|
18
|
+
object.pretty_inspect
|
19
|
+
|
20
|
+
object.pretty_inspect(n), where n is the maximum depth to display
|
21
|
+
email: mjwelchphd@gmail.com
|
18
22
|
executables: []
|
19
23
|
extensions: []
|
20
24
|
extra_rdoc_files: []
|
@@ -22,7 +26,7 @@ files:
|
|
22
26
|
- lib/pretty_inspect.rb
|
23
27
|
homepage: http://rubygems.org/gems/pretty_inspect
|
24
28
|
licenses:
|
25
|
-
-
|
29
|
+
- Ruby
|
26
30
|
metadata: {}
|
27
31
|
post_install_message:
|
28
32
|
rdoc_options: []
|
@@ -30,17 +34,17 @@ require_paths:
|
|
30
34
|
- lib
|
31
35
|
required_ruby_version: !ruby/object:Gem::Requirement
|
32
36
|
requirements:
|
33
|
-
- -
|
37
|
+
- - ">="
|
34
38
|
- !ruby/object:Gem::Version
|
35
39
|
version: '0'
|
36
40
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
41
|
requirements:
|
38
|
-
- -
|
42
|
+
- - ">="
|
39
43
|
- !ruby/object:Gem::Version
|
40
44
|
version: '0'
|
41
45
|
requirements: []
|
42
46
|
rubyforge_project:
|
43
|
-
rubygems_version: 2.
|
47
|
+
rubygems_version: 2.7.6
|
44
48
|
signing_key:
|
45
49
|
specification_version: 4
|
46
50
|
summary: Pretty Inspect (pretty_inspect) is an extension to Object::inspect.
|