End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Kernel#p
p(obj) → obj
p(obj1, obj2, ...) → [obj, ...]
p() → nil
io.c
View on GitHub ↗
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);
}
For each object, directly writes obj.inspect followed by a newline to the program’s standard output.
Example
S = Struct.new(:name, :state) s = S['dave', 'TX'] p s
produces:
Example
#<S name="dave", state="TX">