Niklas,

Thanks for opening my eyes man. Saving it to an array makes the code 
dryer in less lines and makes it more proof to threaded environments. 
Seems well worth the extra line of code if you ask me.

Thanks for the help.

Andy


Niklas Cathor wrote in post #961493:
> On Mon, 2010-11-15 at 18:05 +0900, Andy Tolle wrote:
>> over his set?
> No, the database is not queried every time. The reason I was suggesting
> to use an array is that it that that way you don't need to handle that
> specially. It works like any other ruby array, unlike the Mysql::Result,
> which you need to reset before iterating again. So if you're about to
> iterate over the result multiple times, possibly in different places
> it's save to either
>   a) make your custom iterator, rewinding the result set afterwards
>     OR
>   b) use a standard ruby type, such as Array
>
> a) might look like this (ugly monkey patch):
>
> class Mysql::Result
>   def my_each_hash(&block)
>     each_hash(&block) ; data_seek(0)
>   end
> end
>
> Be warned though: this might give you trouble in a threaded environment.

-- 
Posted via http://www.ruby-forum.com/.