From: Matthew Kerwin Date: 2013-02-16T19:49:31+09:00 Subject: Re: Confusion with Ruby printing mechanics. --f46d0408da07015fa504d5d53f59 Content-Type: text/plain; charset=ISO-8859-1 Print doesn't append a newline, so the puts'd nil is tacked onto the end of the 'hi' I'd write more, but I hate typing on my phone. Sent from my phone, so excuse the typos. On Feb 16, 2013 8:42 PM, "Love U Ruby" wrote: > Here I just played to see how printing statement behaves with "nil" > values. Here we go: > > >> p nil > nil > => nil #good as expected. > >> puts nil > #as nil.to_s causes the "blank" in the first line. > => nil #good as expected. > >> p puts nil > #as nil.to_s causes the "blank" in the first line > nil > => nil # good as expected, as p works here on the return value of puts. > > ========================= > > Confusion begins with the below : > > >> p(puts(print("hi"))) > hi > nil > => nil # this is the actual output. > > But from the above analysis I expected the below: > > >> p(puts(print("hi"))) > hi > > nil > => nil > > Could you explain the gap between my assumption and the actual one? > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > > --f46d0408da07015fa504d5d53f59 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Print doesn't append a newline, so the puts'd nil is tacked onto= the end of the 'hi'

I'd write more, but I hate typing on my phone.

Sent from my phone, so excuse the typos.

On Feb 16, 2013 8:42 PM, "Love U Ruby"= <lists@ruby-forum.com> w= rote:
Here I just played to see how printing statement behaves with "nil&quo= t;
values. Here we go:

>> p nil
nil
=3D> nil #good as expected.
>> puts nil
=A0 =A0 =A0 =A0#as nil.to_s causes the "blank" in the first line.=
=3D> nil #good as expected.
>> p puts nil
=A0 =A0 #as nil.to_s causes the "blank" in the first line
nil
=3D> nil # good as expected, as p works here on the return value of puts= .

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=

Confusion begins with the below :

>> p(puts(print("hi")))
hi
nil
=3D> nil # this is the actual output.

But from the above analysis I expected the below:

>> p(puts(print("hi")))
hi

nil
=3D> nil

Could you explain the gap between my assumption and the actual one?

Thanks.

--
Posted via http://= www.ruby-forum.com/.

--f46d0408da07015fa504d5d53f59--