Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Kernel#p

p(object) → obj
p(*objects) → array of objects
p → nil

For each object obj, executes:

Example
$stdout.write(obj.inspect, "\n")

With one object given, returns the object; with multiple objects given, returns an array containing the objects; with no object given, returns nil.

Examples:

Example
r = Range.new(0, 4)
p r                 # => 0..4
p [r, r, r]         # => [0..4, 0..4, 0..4]
p                   # => nil

Output:

Example
0..4
[0..4, 0..4, 0..4]
See also #open #Pathname #__method__ #pp also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0