From: Daniel N Date: 2007-07-26T10:12:03+09:00 Subject: Re: How to properly iterate an array (using TDD) ------=_Part_155746_25406532.1185412325857 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/26/07, Al Cholic wrote: > > Hello, > > Im trying to iterate an array, but its not working. > > I have setup a test that looks like this: > > def test_getting_component_info > original = ["1 1 C1 0805,C56p 0805", "2 5 C2,C5,C19,C24,C25 > 0603,C0.01 0603 50V +/-10% ECU-V1H103KBV Panasonic 2011032601"] > expected = "5\n9" > > assert_equal(expected, get_component_info(original)) > end > > The string elements are seperated by tabs. > > > And here is my method that I am testing: > > def get_component_info(bom) > bom.each { |line| > line.split("\t").length > } > end > > And here is what the test script says: > <"5\n9"> expected but was > <["1\t1\tC1\t0805,C56p\t0805", > "2\t5\tC2,C5,C19,C24,C25\t0603,C0.01\t0603\t50V > +/-10%\tECU-V1H103KBV\tPanasonic\t2011032601"]>. > > The mehtod seems to be returning the same array that im passing in. > What am I doing wrong? Without the array iteration Im able to split it > by tabs and do everything but as soon as I put the iteration block, > everything messes up. The get_component_info method is returning the bom variable because that was the last thing evaluated. bom.each{ stuff } will return bom if it's the last statement. I'm not sure where the "5\n9" comes from. I don't see anything in the array or the get_component_info method that would give this value. What are you trying to do? Cheers Daniel ------=_Part_155746_25406532.1185412325857--