On Thu, Oct 6, 2011 at 2:02 PM, Sam Duncan <sduncan / wetafx.co.nz> wrote:
> On 07/10/11 09:56, itankgo itankgo wrote:
>>
>> Can't understand:
>>
>> # coding: cp1251
>>
>> x =3D puts 'bbb'
>> puts x
>>
>> out needs to be:
>>
>> =3D> =A0bbb
>> =3D> =A0nil
>>
>> But nil is not returned(bbb displayed),only empty line instead of nil is
>> on screen.
>>
>> ruby v.1.9.2-p180
>>
> Try
>
> x =3D puts 'bbb'
>
> puts x.inspect

The docs for IO#print, IO#puts, and OI#inspect help understand what's
going on here.  puts outputs myobject.to_s followed by an added
newline.   x is nil, the string representation of nil is '', so puts x
correctly outputs "\n".  As Sam noted, the inspect method is what's
needed for these situations.

--=20
=A0 Carina