pp 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pp.rb +75 -32
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ae81116a5438a08aca95879913585f76a9d96603ad30bbd5b724479ba0adeca
|
4
|
+
data.tar.gz: 3d5bca0ec8f49203d50cd6bb386f0666895bc9cec73f18e3fe0118c1e24bf12a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e843b0b52ef64b1b467b131968f39e9ec643f877459752c31affeec80184dc1ade4b1ce0b0a48a0c2e78a1fc29ca9f65355ec887b6ab4a50024edab0b0c4f525
|
7
|
+
data.tar.gz: 610bcf764e874ff0237a551d3d2bf2d1a4627c37eb2bba45fb1d64591b111c7693549c0cf22372599a3dbbbb27701f7754e50cc0fbc01f168a8cf8cc6aded6e0
|
data/lib/pp.rb
CHANGED
@@ -63,7 +63,8 @@ require 'prettyprint'
|
|
63
63
|
|
64
64
|
class PP < PrettyPrint
|
65
65
|
|
66
|
-
|
66
|
+
# The version string
|
67
|
+
VERSION = "0.6.3"
|
67
68
|
|
68
69
|
# Returns the usable width for +out+.
|
69
70
|
# As the width of +out+:
|
@@ -138,26 +139,19 @@ class PP < PrettyPrint
|
|
138
139
|
end
|
139
140
|
end
|
140
141
|
|
142
|
+
# Module that defines helper methods for pretty_print.
|
141
143
|
module PPMethods
|
142
144
|
|
143
145
|
# Yields to a block
|
144
146
|
# and preserves the previous set of objects being printed.
|
145
147
|
def guard_inspect_key
|
146
|
-
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
if Thread.current[:__recursive_key__][:inspect] == nil
|
151
|
-
Thread.current[:__recursive_key__][:inspect] = {}.compare_by_identity
|
152
|
-
end
|
153
|
-
|
154
|
-
save = Thread.current[:__recursive_key__][:inspect]
|
155
|
-
|
148
|
+
recursive_state = Thread.current[:__recursive_key__] ||= {}.compare_by_identity
|
149
|
+
save = recursive_state[:inspect] ||= {}.compare_by_identity
|
156
150
|
begin
|
157
|
-
|
151
|
+
recursive_state[:inspect] = {}.compare_by_identity
|
158
152
|
yield
|
159
153
|
ensure
|
160
|
-
|
154
|
+
recursive_state[:inspect] = save
|
161
155
|
end
|
162
156
|
end
|
163
157
|
|
@@ -165,9 +159,8 @@ class PP < PrettyPrint
|
|
165
159
|
# to be pretty printed. Used to break cycles in chains of objects to be
|
166
160
|
# pretty printed.
|
167
161
|
def check_inspect_key(id)
|
168
|
-
Thread.current[:__recursive_key__]
|
169
|
-
|
170
|
-
Thread.current[:__recursive_key__][:inspect].include?(id)
|
162
|
+
recursive_state = Thread.current[:__recursive_key__] or return false
|
163
|
+
recursive_state[:inspect]&.include?(id)
|
171
164
|
end
|
172
165
|
|
173
166
|
# Adds the object_id +id+ to the set of objects being pretty printed, so
|
@@ -181,6 +174,24 @@ class PP < PrettyPrint
|
|
181
174
|
Thread.current[:__recursive_key__][:inspect].delete id
|
182
175
|
end
|
183
176
|
|
177
|
+
private def guard_inspect(object)
|
178
|
+
recursive_state = Thread.current[:__recursive_key__]
|
179
|
+
|
180
|
+
if recursive_state&.key?(:inspect)
|
181
|
+
begin
|
182
|
+
push_inspect_key(object)
|
183
|
+
yield
|
184
|
+
ensure
|
185
|
+
pop_inspect_key(object) unless PP.sharing_detection
|
186
|
+
end
|
187
|
+
else
|
188
|
+
guard_inspect_key do
|
189
|
+
push_inspect_key(object)
|
190
|
+
yield
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
184
195
|
# Adds +obj+ to the pretty printing buffer
|
185
196
|
# using Object#pretty_print or Object#pretty_print_cycle.
|
186
197
|
#
|
@@ -196,15 +207,12 @@ class PP < PrettyPrint
|
|
196
207
|
return
|
197
208
|
end
|
198
209
|
|
199
|
-
|
200
|
-
push_inspect_key(obj)
|
210
|
+
guard_inspect(obj) do
|
201
211
|
group do
|
202
212
|
obj.pretty_print self
|
203
213
|
rescue NoMethodError
|
204
214
|
text Kernel.instance_method(:inspect).bind_call(obj)
|
205
215
|
end
|
206
|
-
ensure
|
207
|
-
pop_inspect_key(obj) unless PP.sharing_detection
|
208
216
|
end
|
209
217
|
end
|
210
218
|
|
@@ -259,15 +267,20 @@ class PP < PrettyPrint
|
|
259
267
|
def seplist(list, sep=nil, iter_method=:each) # :yield: element
|
260
268
|
sep ||= lambda { comma_breakable }
|
261
269
|
first = true
|
270
|
+
kwsplat = EMPTY_KWHASH
|
262
271
|
list.__send__(iter_method) {|*v|
|
263
272
|
if first
|
264
273
|
first = false
|
265
274
|
else
|
266
275
|
sep.call
|
267
276
|
end
|
268
|
-
|
277
|
+
kwsplat ? yield(*v, **kwsplat) : yield(*v)
|
269
278
|
}
|
270
279
|
end
|
280
|
+
EMPTY_KWHASH = if RUBY_VERSION >= "3.0"
|
281
|
+
{}.freeze
|
282
|
+
end
|
283
|
+
private_constant :EMPTY_KWHASH
|
271
284
|
|
272
285
|
# A present standard failsafe for pretty printing any given Object
|
273
286
|
def pp_object(obj)
|
@@ -300,12 +313,10 @@ class PP < PrettyPrint
|
|
300
313
|
# A pretty print for a pair of Hash
|
301
314
|
def pp_hash_pair(k, v)
|
302
315
|
if Symbol === k
|
303
|
-
|
304
|
-
|
305
|
-
text "#{k.to_s.inspect}:"
|
306
|
-
else
|
307
|
-
text "#{k}:"
|
316
|
+
if k.inspect.match?(%r[\A:["$@!]|[%&*+\-\/<=>@\]^`|~]\z])
|
317
|
+
k = k.to_s.inspect
|
308
318
|
end
|
319
|
+
text "#{k}:"
|
309
320
|
else
|
310
321
|
pp k
|
311
322
|
text ' '
|
@@ -377,7 +388,8 @@ class PP < PrettyPrint
|
|
377
388
|
# This method should return an array of names of instance variables as symbols or strings as:
|
378
389
|
# +[:@a, :@b]+.
|
379
390
|
def pretty_print_instance_variables
|
380
|
-
instance_variables
|
391
|
+
ivars = respond_to?(:instance_variables_to_inspect) ? instance_variables_to_inspect : instance_variables
|
392
|
+
ivars.sort
|
381
393
|
end
|
382
394
|
|
383
395
|
# Is #inspect implementation using #pretty_print.
|
@@ -420,6 +432,28 @@ class Hash # :nodoc:
|
|
420
432
|
end
|
421
433
|
end
|
422
434
|
|
435
|
+
if defined?(Set)
|
436
|
+
if set_pp = Set.instance_method(:initialize).source_location
|
437
|
+
set_pp = !set_pp.first.end_with?("/set.rb") # not defined in set.rb
|
438
|
+
else
|
439
|
+
set_pp = true # defined in C
|
440
|
+
end
|
441
|
+
end
|
442
|
+
class Set # :nodoc:
|
443
|
+
def pretty_print(pp) # :nodoc:
|
444
|
+
pp.group(1, "#{self.class.name}[", ']') {
|
445
|
+
pp.seplist(self) { |o|
|
446
|
+
pp.pp o
|
447
|
+
}
|
448
|
+
}
|
449
|
+
end
|
450
|
+
|
451
|
+
def pretty_print_cycle(pp) # :nodoc:
|
452
|
+
name = self.class.name
|
453
|
+
pp.text(empty? ? "#{name}[]" : "#{name}[...]")
|
454
|
+
end
|
455
|
+
end if set_pp
|
456
|
+
|
423
457
|
class << ENV # :nodoc:
|
424
458
|
def pretty_print(q) # :nodoc:
|
425
459
|
h = {}
|
@@ -450,6 +484,13 @@ class Struct # :nodoc:
|
|
450
484
|
end
|
451
485
|
end
|
452
486
|
|
487
|
+
verbose, $VERBOSE = $VERBOSE, nil
|
488
|
+
begin
|
489
|
+
has_data_define = defined?(Data.define)
|
490
|
+
ensure
|
491
|
+
$VERBOSE = verbose
|
492
|
+
end
|
493
|
+
|
453
494
|
class Data # :nodoc:
|
454
495
|
def pretty_print(q) # :nodoc:
|
455
496
|
class_name = PP.mcall(self, Kernel, :class).name
|
@@ -482,15 +523,17 @@ class Data # :nodoc:
|
|
482
523
|
def pretty_print_cycle(q) # :nodoc:
|
483
524
|
q.text sprintf("#<data %s:...>", PP.mcall(self, Kernel, :class).name)
|
484
525
|
end
|
485
|
-
end if
|
526
|
+
end if has_data_define
|
486
527
|
|
487
528
|
class Range # :nodoc:
|
488
529
|
def pretty_print(q) # :nodoc:
|
489
|
-
|
530
|
+
begin_nil = self.begin == nil
|
531
|
+
end_nil = self.end == nil
|
532
|
+
q.pp self.begin if !begin_nil || end_nil
|
490
533
|
q.breakable ''
|
491
534
|
q.text(self.exclude_end? ? '...' : '..')
|
492
535
|
q.breakable ''
|
493
|
-
q.pp self.end if
|
536
|
+
q.pp self.end if !end_nil || begin_nil
|
494
537
|
end
|
495
538
|
end
|
496
539
|
|
@@ -619,7 +662,7 @@ class MatchData # :nodoc:
|
|
619
662
|
end
|
620
663
|
|
621
664
|
if defined?(RubyVM::AbstractSyntaxTree)
|
622
|
-
class RubyVM::AbstractSyntaxTree::Node
|
665
|
+
class RubyVM::AbstractSyntaxTree::Node # :nodoc:
|
623
666
|
def pretty_print_children(q, names = [])
|
624
667
|
children.zip(names) do |c, n|
|
625
668
|
if n
|
@@ -684,7 +727,7 @@ module Kernel
|
|
684
727
|
|
685
728
|
# prints arguments in pretty form.
|
686
729
|
#
|
687
|
-
# pp returns argument(s).
|
730
|
+
# +#pp+ returns argument(s).
|
688
731
|
def pp(*objs)
|
689
732
|
objs.each {|obj|
|
690
733
|
PP.pp(obj)
|
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.6.
|
4
|
+
version: 0.6.3
|
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:
|
11
|
+
date: 2025-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prettyprint
|
@@ -42,7 +42,7 @@ licenses:
|
|
42
42
|
metadata:
|
43
43
|
homepage_uri: https://github.com/ruby/pp
|
44
44
|
source_code_uri: https://github.com/ruby/pp
|
45
|
-
post_install_message:
|
45
|
+
post_install_message:
|
46
46
|
rdoc_options: []
|
47
47
|
require_paths:
|
48
48
|
- lib
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
60
|
rubygems_version: 3.5.11
|
61
|
-
signing_key:
|
61
|
+
signing_key:
|
62
62
|
specification_version: 4
|
63
63
|
summary: Provides a PrettyPrinter for Ruby objects
|
64
64
|
test_files: []
|