Skip to content
instance method

Kernel#p

[T < ::_Inspect] (T arg0) -> T
(::_Inspect arg0, ::_Inspect arg1, *::_Inspect rest) -> ::Array[::_Inspect]
() -> nil
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]

Kernel#p is designed for debugging purposes. Ruby implementations may define Kernel#p to be uninterruptible in whole or in part. On CRuby, Kernel#p‘s writing of data is uninterruptible.

See also #open #Pathname #__method__ #pp also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0