| Module | PP::ObjectMixin |
| In: |
lib/pp.rb
|
A default pretty printing method for general objects. It calls pretty_print_instance_variables to list instance variables.
If self has a customized (redefined) inspect method, the result of self.inspect is used but it obviously has no line break hints.
This module provides predefined pretty_print methods for some of the most commonly used built-in classes for convenience.
# File lib/pp.rb, line 257
257: def pretty_print(q)
258: if /\(Kernel\)#/ !~ Object.instance_method(:method).bind(self).call(:inspect).inspect
259: q.text self.inspect
260: elsif /\(Kernel\)#/ !~ Object.instance_method(:method).bind(self).call(:to_s).inspect && instance_variables.empty?
261: q.text self.to_s
262: else
263: q.pp_object(self)
264: end
265: end
A default pretty printing method for general objects that are detected as part of a cycle.
# File lib/pp.rb, line 269
269: def pretty_print_cycle(q)
270: q.object_address_group(self) {
271: q.breakable
272: q.text '...'
273: }
274: end
Is inspect implementation using pretty_print. If you implement pretty_print, it can be used as follows.
alias inspect pretty_print_inspect
However, doing this requires that every class that inspect is called on implement pretty_print, or a RuntimeError will be raised.
# File lib/pp.rb, line 291
291: def pretty_print_inspect
292: if /\(PP::ObjectMixin\)#/ =~ Object.instance_method(:method).bind(self).call(:pretty_print).inspect
293: raise "pretty_print is not overridden for #{self.class}"
294: end
295: PP.singleline_pp(self, '')
296: end