Kernel#pp

pp(*objects) -> objects
Returns: Array · Added in v1.8.1 · Updated March 13, 2026 · Kernel Methods
output pretty-print debugging console

pp is a Kernel method that outputs one or more objects to standard output using a pretty-printed format. Unlike puts or p, it uses the PP library to format complex data structures in a readable, nested way that reveals structure without overwhelming output.

Syntax

pp object
pp object1, object2, object3
pp *array

Parameters

ParameterTypeDescription
*objectsObject(s)One or more objects to output. Each object is pretty-printed on its own line.

Examples

Basic Usage

require 'pp'

pp "Hello, World!"
# => "Hello, World!"

pp 42
# => 42

Pretty-Printing Arrays

require 'pp'

arr = [1, 2, 3, 4, 5]
pp arr
# => [1, 2, 3, 4, 5]

nested = [1, [2, 3], [[4, 5]]]
pp nested
# => [1, [2, 3], [[4, 5]]]

Pretty-Printing Hashes

require 'pp'

hash = { name: "Alice", age: 30, city: "London" }
pp hash
# => {:name => "Alice", :age => 30, :city => "London"}

deep_hash = { user: { profile: { name: "Bob", settings: { theme: "dark" } } } }
pp deep_hash
# => {:user => {:profile => {:name => "Bob", :settings => {:theme => "dark"}}}}

Inspecting Objects

require 'pp'

class Person
  def initialize(name, age)
    @name = name
    @age = age
  end
end

pp Person.new("Charlie", 25)
# => #<Person:0x00007f8a2c3d4020 @name=\"Charlie\", @age=25>

Common Patterns

Debugging Data Structures

require 'pp'

def process_request(params)
  pp params
  # Output clearly shows nested structure
  result = transform(params)
  pp result
  result
end

Comparing Output Methods

require 'pp'

data = { users: [{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }] }

puts data
# {:users=>[{:id=>1, :name=>\"Alice\"}, {:id=>2, :name=>\"Bob\"}]}

p data
# {:users=>[{:id=>1, :name=>\"Alice\"}, {:id=>2, :name=>\"Bob\"}]}

pp data
# {:users =>
#   [{:id => 1, :name => \"Alice\"},
#    {:id => 2, :name => \"Bob\"}]}

Pretty-Printing Large Arrays

require 'pp'

large_array = (1..20).to_a
pp large_array
# => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

pp vs p vs puts

MethodFormatReturn ValueBest For
putsto_snilUser-facing output
pinspectThe objectQuick debugging
ppPrettyPrintThe objectComplex data structures

See Also