Method: Kernel#p

Defined in:
io.c

#p(obj) ⇒ Object #p(obj1, obj2, ...) ⇒ Array #pnil

For each object, directly writes obj.inspect followed by a newline to the program’s standard output.

S = Struct.new(:name, :state)
s = S['dave', 'TX']
p s

produces:

#<S name="dave", state="TX">

Overloads:

  • #p(obj) ⇒ Object

    Returns:

  • #p(obj1, obj2, ...) ⇒ Array

    Returns:

  • #pnil

    Returns:

    • (nil)


7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
# File 'io.c', line 7999

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);
}