pretty_inspect 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/pretty_inspect.rb +54 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a948fef234fb447640b003c2e791d48e09a2ad68
|
4
|
+
data.tar.gz: a01b4aff91843ae8d5eca50e5c58667db91d6ea8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bca9842c58adfe5aecb48665808c67512eee07f60993dc70f053a50fad1be4f1cc9094294157baaf5812975b92c1b913cb319612576c903ad416e646d85a75a
|
7
|
+
data.tar.gz: d5a9f54be9e0f1a3b50c95d210314843c4cd6b6b7671e283c1ba82acc3ad1bff107c09f94e34a21837c5be1459eb8658824632673fc3f1d2e7b62c894e578232
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Pretty Inspect
|
2
|
+
|
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> puts (['a','b',{1=>'a',2=>'b'},'c'].pretty_inspect)
|
14
|
+
# [
|
15
|
+
# "a",
|
16
|
+
# "b",
|
17
|
+
# {
|
18
|
+
# 1 => "a",
|
19
|
+
# 2 => "b"
|
20
|
+
# },
|
21
|
+
# "c"
|
22
|
+
# ]
|
23
|
+
# => nil
|
24
|
+
# irb>
|
25
|
+
|
26
|
+
def pretty_inspect_core(values, level, output)
|
27
|
+
case values
|
28
|
+
when Array
|
29
|
+
output << "[\n"
|
30
|
+
count = values.size
|
31
|
+
values.each do |value|
|
32
|
+
output << " "*(level+2)
|
33
|
+
pretty_inspect_core(value,level+2,output)
|
34
|
+
output << (if (count -= 1) > 0 then ",\n" else "\n" end)
|
35
|
+
end
|
36
|
+
output << "%s]"%(" "*level)
|
37
|
+
when Hash
|
38
|
+
output << "{\n"
|
39
|
+
count = values.size
|
40
|
+
values.each do |key,value|
|
41
|
+
output << "%s%s => "%[" "*(level+2),key.inspect]
|
42
|
+
pretty_inspect_core(value,level+2,output)
|
43
|
+
output << (if (count -= 1) > 0 then ",\n" else "\n" end)
|
44
|
+
end
|
45
|
+
output << "%s}"%(" "*level)
|
46
|
+
else
|
47
|
+
output << values.inspect
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def pretty_inspect
|
52
|
+
pretty_inspect_core(self, 0, "")
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pretty_inspect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael J. Welch, Ph.D.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-18 00:00:00.000000000 Z
|
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.
|
15
|
+
email: rubygems@czarmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/pretty_inspect.rb
|
21
|
+
homepage: http://rubygems.org/gems/pretty_inspect
|
22
|
+
licenses:
|
23
|
+
- GPL
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.0.7
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Pretty Inspect (pretty_inspect) is an extension to Object::inspect.
|
45
|
+
test_files: []
|