pp 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/{LICENSE.txt → BSDL} +3 -3
  3. data/COPYING +56 -0
  4. data/lib/pp.rb +59 -15
  5. data/pp.gemspec +2 -1
  6. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05c96009c03ef3d1fb5542a17f2833a93b128a7579380a4c608384fc6232d5a7
4
- data.tar.gz: 629c3161e24420959ea1946d612f22ce4b73694f7e5c805499fb166f75cd9de8
3
+ metadata.gz: f7baebc9ed9b6d7e6a59bab9519127ddae100eb3d8f69f34e2f425a8676f4de2
4
+ data.tar.gz: fd88755cc44af04429d8295ddbbf0e5f607e140fcedcca3f5f93130cd619a845
5
5
  SHA512:
6
- metadata.gz: 98484471668309f5a8822bc9206cff58534431274db6d0cb828876417fdf4f4e932f61894d613aced33246ee168b85c4d6c2d8d38faaf5bdb0fae6fcea55bc59
7
- data.tar.gz: 4fd410d4b90723eaaf32e221d219ee88db428ecc7b133f0b873aa9625045bc7e83d55e04edeb0d715ed3d9a32d71cb2ae5d0aaad4ebf981f05424a4dfbfebb5c
6
+ metadata.gz: 5839273be7f644375b772d91608303d003a15925006c5b65b4f25fca5d5cba3e0e22ea53749126d401e11484607efe95de2c969ea9f7b58a1a9a5eec9948282b
7
+ data.tar.gz: e5c76b514108b430d939767308cc078915ab2fb4f796cbabf65d58ab2355c018b5882378db7edd96155cf60b20971be40cfaef32a68ff1315abc450bac89218f
@@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
4
4
  modification, are permitted provided that the following conditions
5
5
  are met:
6
6
  1. Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
7
+ notice, this list of conditions and the following disclaimer.
8
8
  2. Redistributions in binary form must reproduce the above copyright
9
- notice, this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
11
 
12
12
  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
13
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
data/COPYING ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a. place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b. use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c. give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d. make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a. distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b. accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c. give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d. make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/lib/pp.rb CHANGED
@@ -63,7 +63,7 @@ require 'prettyprint'
63
63
 
64
64
  class PP < PrettyPrint
65
65
 
66
- VERSION = "0.5.0"
66
+ VERSION = "0.6.0"
67
67
 
68
68
  # Returns the usable width for +out+.
69
69
  # As the width of +out+:
@@ -93,7 +93,7 @@ class PP < PrettyPrint
93
93
  #
94
94
  # PP.pp returns +out+.
95
95
  def PP.pp(obj, out=$>, width=width_for(out))
96
- q = PP.new(out, width)
96
+ q = new(out, width)
97
97
  q.guard_inspect_key {q.pp obj}
98
98
  q.flush
99
99
  #$pp = q
@@ -189,7 +189,7 @@ class PP < PrettyPrint
189
189
  def pp(obj)
190
190
  # If obj is a Delegator then use the object being delegated to for cycle
191
191
  # detection
192
- obj = obj.__getobj__ if defined?(::Delegator) and obj.is_a?(::Delegator)
192
+ obj = obj.__getobj__ if defined?(::Delegator) and ::Delegator === obj
193
193
 
194
194
  if check_inspect_key(obj)
195
195
  group {obj.pretty_print_cycle self}
@@ -198,7 +198,11 @@ class PP < PrettyPrint
198
198
 
199
199
  begin
200
200
  push_inspect_key(obj)
201
- group {obj.pretty_print self}
201
+ group do
202
+ obj.pretty_print self
203
+ rescue NoMethodError
204
+ text Kernel.instance_method(:inspect).bind_call(obj)
205
+ end
202
206
  ensure
203
207
  pop_inspect_key(obj) unless PP.sharing_detection
204
208
  end
@@ -286,16 +290,42 @@ class PP < PrettyPrint
286
290
  group(1, '{', '}') {
287
291
  seplist(obj, nil, :each_pair) {|k, v|
288
292
  group {
289
- pp k
290
- text '=>'
291
- group(1) {
292
- breakable ''
293
- pp v
294
- }
293
+ pp_hash_pair k, v
295
294
  }
296
295
  }
297
296
  }
298
297
  end
298
+
299
+ if RUBY_VERSION >= '3.4.'
300
+ # A pretty print for a pair of Hash
301
+ def pp_hash_pair(k, v)
302
+ if Symbol === k
303
+ sym_s = k.inspect
304
+ if sym_s[1].match?(/["$@!]/) || sym_s[-1].match?(/[%&*+\-\/<=>@\]^`|~]/)
305
+ text "#{k.to_s.inspect}:"
306
+ else
307
+ text "#{k}:"
308
+ end
309
+ else
310
+ pp k
311
+ text ' '
312
+ text '=>'
313
+ end
314
+ group(1) {
315
+ breakable
316
+ pp v
317
+ }
318
+ end
319
+ else
320
+ def pp_hash_pair(k, v)
321
+ pp k
322
+ text '=>'
323
+ group(1) {
324
+ breakable ''
325
+ pp v
326
+ }
327
+ end
328
+ end
299
329
  end
300
330
 
301
331
  include PPMethods
@@ -422,14 +452,28 @@ end
422
452
 
423
453
  class Data # :nodoc:
424
454
  def pretty_print(q) # :nodoc:
425
- q.group(1, sprintf("#<data %s", PP.mcall(self, Kernel, :class).name), '>') {
426
- q.seplist(PP.mcall(self, Data, :members), lambda { q.text "," }) {|member|
455
+ class_name = PP.mcall(self, Kernel, :class).name
456
+ class_name = " #{class_name}" if class_name
457
+ q.group(1, "#<data#{class_name}", '>') {
458
+
459
+ members = PP.mcall(self, Kernel, :class).members
460
+ values = []
461
+ members.select! do |member|
462
+ value = begin
463
+ values << __send__(member)
464
+ true
465
+ rescue NoMethodError
466
+ false
467
+ end
468
+ end
469
+
470
+ q.seplist(members.zip(values), lambda { q.text "," }) {|(member, value)|
427
471
  q.breakable
428
472
  q.text member.to_s
429
473
  q.text '='
430
474
  q.group(1) {
431
475
  q.breakable ''
432
- q.pp public_send(member)
476
+ q.pp value
433
477
  }
434
478
  }
435
479
  }
@@ -438,11 +482,11 @@ class Data # :nodoc:
438
482
  def pretty_print_cycle(q) # :nodoc:
439
483
  q.text sprintf("#<data %s:...>", PP.mcall(self, Kernel, :class).name)
440
484
  end
441
- end if "3.2" <= RUBY_VERSION
485
+ end if defined?(Data.define)
442
486
 
443
487
  class Range # :nodoc:
444
488
  def pretty_print(q) # :nodoc:
445
- q.pp self.begin
489
+ q.pp self.begin if self.begin
446
490
  q.breakable ''
447
491
  q.text(self.exclude_end? ? '...' : '..')
448
492
  q.breakable ''
data/pp.gemspec CHANGED
@@ -22,7 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.metadata["source_code_uri"] = spec.homepage
23
23
 
24
24
  spec.files = %w[
25
- LICENSE.txt
25
+ BSDL
26
+ COPYING
26
27
  lib/pp.rb
27
28
  pp.gemspec
28
29
  ]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanaka Akira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-07 00:00:00.000000000 Z
11
+ date: 2024-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prettyprint
@@ -31,7 +31,8 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - LICENSE.txt
34
+ - BSDL
35
+ - COPYING
35
36
  - lib/pp.rb
36
37
  - pp.gemspec
37
38
  homepage: https://github.com/ruby/pp
@@ -41,7 +42,7 @@ licenses:
41
42
  metadata:
42
43
  homepage_uri: https://github.com/ruby/pp
43
44
  source_code_uri: https://github.com/ruby/pp
44
- post_install_message:
45
+ post_install_message:
45
46
  rdoc_options: []
46
47
  require_paths:
47
48
  - lib
@@ -56,8 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
57
  - !ruby/object:Gem::Version
57
58
  version: '0'
58
59
  requirements: []
59
- rubygems_version: 3.5.0.dev
60
- signing_key:
60
+ rubygems_version: 3.5.11
61
+ signing_key:
61
62
  specification_version: 4
62
63
  summary: Provides a PrettyPrinter for Ruby objects
63
64
  test_files: []