How "puts" statement works in Ruby? -
How "puts" statement works in Ruby? -
i knew puts homecoming nil
itself.
but knowing fact have started play around it. here is:
>> puts => nil # good, doing expected. >> puts 15 15 => nil # nil puts , 15 printed,as assigned do. perfect still. >> puts = 5 + 2 7 => nil # still good.
now bit more puts
see how robust is.
>> puts a= 5 + 2;b= 2+3 7 => 5 #ahh! nil? >> puts a= 5 + 2;b= 2+3;c= 4+8 7 => 12 # 1 time again no nil. confusion created here why 12 , 7 only, how 5 has been skipped?
how puts
nil
value has been suppressed ?
okay, lets test way nil
has been gone.
>> x=puts a= 5 + 2;b= 2+3;c= 4+8 7 => 12 >> puts x => nil # humm, nil there. why not nil => nil? confusion here 1 time again goes up. nil it?
can help me saying actual behaviour of puts
in ruby's world?
the repl, irb
assume, evaluating statement(s) come in , displaying value of lastly statement evaluated.
consider this:
>> p = puts "hello"; 5 hello => 5 >> p => nil
puts
still returning nil
repl displaying result of lastly statement, 5
ruby ruby-1.9.3
Comments
Post a Comment