On Mar 17, 2011, at 10:24 , Jes=FAs Gabriel y Gal=E1n wrote:

> On Thu, Mar 17, 2011 at 6:02 PM, Yu-Hsuan Lai <raincolee / gmail.com> =
wrote:
>> I read the RDoc and it says:
>> For each object, directly writes *obj*.inspect followed by the =
current
>> output record separator to the program=91s standard output.
>>=20
>> But my $\ is surely nil, it still append a newline after output.
>> ("output record separator" is $\, right?)
>> Why does it do this?
>=20
> Looking into Ruby 1.8.7's source code I see this in io.c:
>=20
> void
> rb_p(obj)                       /* for debug print within C code */
>    VALUE obj;
> {
>    rb_io_write(rb_stdout, rb_obj_as_string(rb_inspect(obj)));
>    rb_io_write(rb_stdout, rb_default_rs);
> }
>=20
> This is the function called by the function defined as 'p'. As you can
> see it's outputting the rb_default_rs. Searching for this in the
> source, it's only assigned to here, in io.c:
>=20
> rb_rs =3D rb_default_rs =3D rb_str_new2("\n");
>=20
> So it seems it's assigned to "\n". I don't know if this rb_default_rs
> is assigned to something else somewhere else (a grep -r rb_default_rs
> * only shows the assignment I showed above), maybe someone with more
> knowledge can chime in. If this is not the case, then I guess the
> documentation should say "the default record separator". Anyone?

Couple lines down:

    rb_define_hooked_variable("$\\", &rb_output_rs, 0, rb_str_setter);

That means that rb_output_rs is hooked up to $\ and changing it in ruby =
will bridge to C.