From: Gennady Date: 2003-03-25T04:43:12+09:00 Subject: Re: [puts] - bug or feature? ----- Original Message ----- From: "Meinrad Recheis" Newsgroups: comp.lang.ruby To: "ruby-talk ML" Sent: Monday, March 24, 2003 11:19 AM Subject: [puts] - bug or feature? > hi ruby community, > > i wrote a ruby script and executed it, here are the lines and the results: > puts 3.to_s + 'b' # => 3b [1] equivalent to: (puts(3.to_s + 'b')) puts prints out expression 3.to_s + 'b' converted to String, that is '3b'. > puts (3).to_s + 'b' # => 3 [2] equivalent to: (puts(3)).to_s + 'b') puts prints out expression 3 converted to String, that is '3'. Then expression nil.to_s + 'b' is being evaluated (nil is the return value of puts). There's neither variable assignment nor another puts for the last evaluation, so it is just discarded. > puts ((3).to_s + 'b') # => 3b [3] Same as [1] > > i am confused about that. > i tried that in irb also and i got > > (3).to_s + 'b' > => "3b" By default irb prints out the result of an input expression with 'p', so this is roughly equivalent to explicit expression p ((3).to_s + 'b') This looks like case [3] doesn't it ;-) > > but > > puts (3).to_s + 'b' > 3 > => "b" And this looks like case [2] plus previously discarded value 'b' is printed out with 'p' (again, default irb behaviour). > > cheers > - meinrad > > >