Type:
Class

Pretty-printer for Ruby objects.

Which seems better?

non-pretty-printed output by p is:

1
#<PP:0x81fedf0 @genspace=#<Proc:0x81feda0>, @group_queue=#<PrettyPrint::GroupQueue:0x81fed3c @queue=[[#<PrettyPrint::Group:0x81fed78 @breakables=[], @depth=0, @break=false>], []]>, @buffer=[], @newline="\n", @group_stack=[#<PrettyPrint::Group:0x81fed78 @breakables=[], @depth=0, @break=false>], @buffer_width=0, @indent=0, @maxwidth=79, @output_width=2, @output=#<IO:0x8114ee4>>

pretty-printed output by pp is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#<PP:0x81fedf0
 @buffer=[],
 @buffer_width=0,
 @genspace=#<Proc:0x81feda0>,
 @group_queue=
  #<PrettyPrint::GroupQueue:0x81fed3c
   @queue=
    [[#<PrettyPrint::Group:0x81fed78 @break=false, @breakables=[], @depth=0>],
     []]>,
 @group_stack=
  [#<PrettyPrint::Group:0x81fed78 @break=false, @breakables=[], @depth=0>],
 @indent=0,
 @maxwidth=79,
 @newline="\n",
 @output=#<IO:0x8114ee4>,
 @output_width=2>

I like the latter. If you do too, this library is for you.

Usage

1
2
3
pp(obj)             #=> obj
pp(obj1, obj2, ...) #=> [obj1, obj2, ...]
pp()                #=> nil

output +obj(s)+ to +$>+ in pretty printed format.

It returns +obj(s)+.

Output Customization

To define your customized pretty printing function for your classes, redefine a method pretty_print(pp) in the class. It takes an argument pp which is an instance of the class PP. The method should use PrettyPrint#text, PrettyPrint#breakable, PrettyPrint#nest, PrettyPrint#group and PP::PPMethods#pp to print the object.

Author

Tanaka Akira <akr@m17n.org>

pretty_print
  • References/Ruby on Rails/Ruby/Classes/PP/PP::ObjectMixin

pretty_print(q) Instance Public methods A default pretty printing method for

2025-01-10 15:47:30
singleline_pp
  • References/Ruby on Rails/Ruby/Classes/PP

singleline_pp(obj, out=$>) Class Public methods Outputs obj

2025-01-10 15:47:30
check_inspect_key
  • References/Ruby on Rails/Ruby/Classes/PP/PP::PPMethods

check_inspect_key(id) Instance Public methods

2025-01-10 15:47:30
guard_inspect_key
  • References/Ruby on Rails/Ruby/Classes/PP/PP::PPMethods

guard_inspect_key() Instance Public methods

2025-01-10 15:47:30
pretty_print_instance_variables
  • References/Ruby on Rails/Ruby/Classes/PP/PP::ObjectMixin

pretty_print_instance_variables() Instance Public methods Returns a sorted array

2025-01-10 15:47:30
object_address_group
  • References/Ruby on Rails/Ruby/Classes/PP/PP::PPMethods

object_address_group(obj, &block) Instance Public methods

2025-01-10 15:47:30
pp
  • References/Ruby on Rails/Ruby/Classes/PP

pp(obj, out=$>, width=79) Class Public methods Outputs obj to

2025-01-10 15:47:30
pp
  • References/Ruby on Rails/Ruby/Classes/PP/PP::PPMethods

pp(obj) Instance Public methods Adds obj to the pretty printing

2025-01-10 15:47:30
push_inspect_key
  • References/Ruby on Rails/Ruby/Classes/PP/PP::PPMethods

push_inspect_key(id) Instance Public methods

2025-01-10 15:47:30
pp_hash
  • References/Ruby on Rails/Ruby/Classes/PP/PP::PPMethods

pp_hash(obj) Instance Public methods

2025-01-10 15:47:30