From: "David A. Black" Date: 2007-10-02T19:22:10+09:00 Subject: Re: a = b = c order of evaluation weird Hi -- On Tue, 2 Oct 2007, SpringFlowers AutumnMoon wrote: > i thought if it is > > a = b = c > > due to associativity rule, then it is > > a = (b = c) > > so (b = c) is evaluated first. and then now it will be a = > (evaluated_value) > > now how come when > > a = Array(1..100) > > and to cut off the first 1/3 and last 1/3 of the array to get about 33 > elements, shouldn't we use > > a[0..a.size/2] = a[a.size*2/3..-1] = nil > > as after the last 1/3 is deleted, you got about 66 elements remaining > and we want the other half deleted, to get to 33 elements. However, it > won't work and requires > > a[0..a.size/3] = a[a.size*2/3..-1] = nil > > why is that? Although the = associates to the right, the subscript expressions are evaluated first. So you're really doing: a[0..50] = a[66..-1] = nil David -- Upcoming training from Ruby Power and Light, LLC: * Intro to Ruby on Rails, Edison, NJ, October 23-26 * Advancing with Rails, Edison, NJ, November 6-9 Both taught by David A. Black. See http://www.rubypal.com for more info!