From: Sven Suska Date: 2006-08-03T20:48:16+09:00 Subject: Re: Array#size empties the Array?? Robert Dober wrote: > try not to replace the code, which is equivalent, and run your test > twice > with the same code. > Cheers > Robert Dear Robert, thank you for your quick reply. Although..., being so quick may mean: perhaps too little time to get the point I was trying to make? ;-) You say the code _is_ equivalent. And I say the code _should_be_ equivalent. I definitively found out, that it does not behave "equivalently". You are suggesting to run my test twice. What do you mean by "twice"? Of course, I had already run it plenty of times ..., But anyway, now I have done the following: I copied-and-pasted the whole test-method that contained the mentioned code lines inside my TestCase class, like this: class WierdSizeTest < Test::Unit::TestCase def test1 ... rks = vt.rks p [:rks_length, rks.length] p [:rks_size, rks.size] p [:rks_class, rks.class] p [:rks_item, rks[0]] p [:rks_length, rks.length] p [:rks_size, rks.size] ... end def test2 ... rks = vt.rks p [:rks_length, rks.length] p [:rks_size, rks.size] p [:rks_class, rks.class] p [:rks_item, rks[0]] p [:rks_length, rks.length] p [:rks_size, rks.size] ... end And I also repeated the test with the "equivalent" code exchanged, ie swapped method calls of #length and #size. And what I found was this: The only factor that influenced the output was _the_order_of_the_method_calls_. Or, to put it directly: Whenever rks.size was the _first_ method call on "rks", the output was: [:rks_size, 0] [:rks_length, 0] [:rks_class, Array] [:rks_item, nil] [:rks_length, 0] [:rks_size, 0] And the output was normal otherwise. (as posted in the beginning) Regardless of how many times a test method was repeated. Regardless of the order of test methods. (When one method contained the "corrupted" variant and the other did not.) This all stabilizes the hypothesis, that the Array#size method empties the array when called as the first method after the object obtained. Any more suggestions? Cheers Sven > -- > Deux choses sont infinies : l'univers et la b棚tise humaine ; en ce qui > concerne l'univers, je n'en ai pas acquis la certitude absolue. Well, it seems so ... - but how does this affect this particular case?... :-) -- Posted via http://www.ruby-forum.com/.