From: John Browning Date: 2007-09-05T22:03:38+09:00 Subject: Re: Multiple Assignments: Newbie question --Apple-Mail-28-236734515 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On 5 Sep 2007, at 12:55, Peter Hickman wrote: > Z T wrote: >> When I run my program: >> >> arg1="Ruby", arg2="Rails", arg3="Rails" >> puts "#{arg1}, #{arg2}, #{arg3}" >> >> Why is the output as follow: >> RubyRailsRails, Rails, Rails >> >> What is the reason for this output? Thanks in advance. >> >> > The reason is that assignment returns something. So arg3="Rails" > actually returns the string "Rails" and as the other posters have > pointed out the comma is a way of listing array items. So starting > from the right > > arg1="Ruby", arg2="Rails", arg3="Rails" > > > We do the first assignment (arg3="Rails") which gives us > > arg1="Ruby", arg2="Rails", "Rails" > > We do the second assignment (arg2="Rails") which gives us > > arg1="Ruby", "Rails", "Rails" > > And finally we do the last assignment (arg1="Ruby", "Rails", "Rails") > > Clear as mud :) This could be a stupid question -- and if so please forgive me -- but it seems like the output should be RubyRailsRails, RailsRails, Rails not RubyRailsRails, Rails, Rails So why doesn't arg2 read its right-hand side as an array when arg3 does? allbests, ........................................................................ ............................ John Browning --Apple-Mail-28-236734515--