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
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 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.