Can't understand:
# coding: cp1251
x = puts 'bbb'
puts x
out needs to be:
=> bbb
=> nil
But nil is not returned(bbb displayed),only empty line instead of nil is
on screen.
ruby v.1.9.2-p180
···
--
Posted via http://www.ruby-forum.com/.
Can't understand:
# coding: cp1251
x = puts 'bbb'
puts x
out needs to be:
=> bbb
=> nil
But nil is not returned(bbb displayed),only empty line instead of nil is
on screen.
ruby v.1.9.2-p180
--
Posted via http://www.ruby-forum.com/.
Try
x = puts 'bbb'
puts x.inspect
Sam
On 07/10/11 09:56, itankgo itankgo wrote:
Can't understand:
# coding: cp1251
x = puts 'bbb'
puts xout needs to be:
=> bbb
=> nilBut nil is not returned(bbb displayed),only empty line instead of nil is
on screen.ruby v.1.9.2-p180
IIf you pull up your irb, it does show =>NIL
The empty line is NIL but running it in a command prompt window will only output an empty line.
To prove this put (puts x.to_i)
It will output the value of that line which is "0"
----- Original Message -----
From: itankgo itankgo <itankgo@gmail.com>
To: ruby-talk ML <ruby-talk@ruby-lang.org>
Cc:
Sent: Thursday, October 6, 2011 4:56 PM
Subject: Simply question
Can't understand:
# coding: cp1251
x = puts 'bbb'
puts x
out needs to be:
=> bbb
=> nil
But nil is not returned(bbb displayed),only empty line instead of nil is
on screen.
ruby v.1.9.2-p180
--
Posted via http://www.ruby-forum.com/.
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.
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 = puts 'bbb'
puts xout needs to be:
=> bbb
=> nilBut nil is not returned(bbb displayed),only empty line instead of nil is
on screen.ruby v.1.9.2-p180
Try
x = puts 'bbb'
puts x.inspect
--
Carina