Method: Kernel#p

Defined in:
io.c

#p(object) ⇒ Object #p(*objects) ⇒ Object #pnil

For each object obj, executes:

$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:

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

Output:

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.

Overloads:

  • #p(object) ⇒ Object

    Returns:

  • #pnil

    Returns:

    • (nil)


9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
# File 'io.c', line 9090

static VALUE
rb_f_p(int argc, VALUE *argv, VALUE self)
{
    int i;
    for (i=0; i<argc; i++) {
        VALUE inspected = rb_obj_as_string(rb_inspect(argv[i]));
        rb_uninterruptible(rb_p_write, inspected);
    }
    return rb_p_result(argc, argv);
}