pretty_print(q)
public
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.
Show source
def pretty_print(q)
method_method = Object.instance_method(:method).bind(self)
begin
inspect_method = method_method.call(:inspect)
rescue NameError
end
begin
to_s_method = method_method.call(:to_s)
rescue NameError
end
if inspect_method && /\(Kernel\)#/ !~ inspect_method.inspect
q.text self.inspect
elsif !inspect_method && self.respond_to?(:inspect)
q.text self.inspect
elsif to_s_method && /\(Kernel\)#/ !~ to_s_method.inspect
q.text self.to_s
elsif !to_s_method && self.respond_to?(:to_s)
q.text self.to_s
else
q.pp_object(self)
end
end