Module PP::ObjectMixin
In: pp.rb

Public Instance methods

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.

[Source]

     # File pp.rb, line 243
243:     def pretty_print(q)
244:       if /\(Kernel\)#/ !~ method(:inspect).inspect
245:         q.text self.inspect
246:       elsif /\(Kernel\)#/ !~ method(:to_s).inspect && instance_variables.empty?
247:         q.text self.to_s
248:       else
249:         q.pp_object(self)
250:       end
251:     end

A default pretty printing method for general objects that are detected as part of a cycle.

[Source]

     # File pp.rb, line 255
255:     def pretty_print_cycle(q)
256:       q.object_address_group(self) {
257:         q.breakable
258:         q.text '...'
259:       }
260:     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.

[Source]

     # File pp.rb, line 277
277:     def pretty_print_inspect
278:       if /\(PP::ObjectMixin\)#/ =~ method(:pretty_print).inspect
279:         raise "pretty_print is not overridden."
280:       end
281:       PP.singleline_pp(self, '')
282:     end

Returns a sorted array of instance variable names.

This method should return an array of names of instance variables as symbols or strings as: +[:@a, :@b]+.

[Source]

     # File pp.rb, line 266
266:     def pretty_print_instance_variables
267:       instance_variables.sort
268:     end

Search

Google

Ruby API Docs

Links