- C
- G
- O
- P
- S
Instance Public methods
check_inspect_key(id) Link
Check whether the object_id id
is in the current buffer of objects to be pretty printed. Used to break cycles in chains of objects to be pretty printed.
comma_breakable() Link
A convenience method which is same as follows:
text ','
breakable
guard_inspect_key() Link
Yields to a block and preserves the previous set of objects being printed.
# File ruby/lib/pp.rb, line 145 def guard_inspect_key if Thread.current[:__recursive_key__] == nil Thread.current[:__recursive_key__] = {}.compare_by_identity end if Thread.current[:__recursive_key__][:inspect] == nil Thread.current[:__recursive_key__][:inspect] = {}.compare_by_identity end save = Thread.current[:__recursive_key__][:inspect] begin Thread.current[:__recursive_key__][:inspect] = {}.compare_by_identity yield ensure Thread.current[:__recursive_key__][:inspect] = save end end
object_address_group(obj, &block) Link
A convenience method, like object_group
, but also reformats the Object’s object_id.
object_group(obj) Link
A convenience method which is same as follows:
group(1, '#<' + obj.class.name, '>') { ... }
pop_inspect_key(id) Link
Removes an object from the set of objects being pretty printed.
pp(obj) Link
Adds obj
to the pretty printing buffer using Object#pretty_print or Object#pretty_print_cycle.
Object#pretty_print_cycle is used when obj
is already printed, a.k.a the object reference chain has a cycle.
# File ruby/lib/pp.rb, line 189 def pp(obj) # If obj is a Delegator then use the object being delegated to for cycle # detection obj = obj.__getobj__ if defined?(::Delegator) and obj.is_a?(::Delegator) if check_inspect_key(obj) group {obj.pretty_print_cycle self} return end begin push_inspect_key(obj) group {obj.pretty_print self} ensure pop_inspect_key(obj) unless PP.sharing_detection end end
push_inspect_key(id) Link
Adds the object_id id
to the set of objects being pretty printed, so as to not repeat objects.
seplist(list, sep=nil, iter_method=:each) Link
Adds a separated list. The list is separated by comma with breakable space, by default.
seplist
iterates the list
using iter_method
. It yields each object to the block given for seplist
. The procedure separator_proc
is called between each yields.
If the iteration is zero times, separator_proc
is not called at all.
If separator_proc
is nil or not given, +lambda { comma_breakable
}+ is used. If iter_method
is not given, :each is used.
For example, following 3 code fragments has similar effect.
q.seplist([1,2,3]) {|v| xxx v }
q.seplist([1,2,3], lambda { q.comma_breakable }, :each) {|v| xxx v }
xxx 1
q.comma_breakable
xxx 2
q.comma_breakable
xxx 3
# File ruby/lib/pp.rb, line 255 def seplist(list, sep=nil, iter_method=:each) # :yield: element sep ||= lambda { comma_breakable } first = true list.__send__(iter_method) {|*v| if first first = false else sep.call end RUBY_VERSION >= "3.0" ? yield(*v, **{}) : yield(*v) } end