--=-NClKFSDOfPQG/S1zu9N+
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

This is a mysql specific problem, not ruby. Result#each_hash is just
syntactic sugar for Result#fetch_hash:

  while tag =3D tags.fetch_hash
  end
  # is the same as:
  tags.each_hash do |tag|
  end

Internally each_hash uses fetch_hash as well:
http://rdoc.info/github/luislavena/mysql-gem/master/Mysql/Result#each_hash-=
instance_method

One way of solving this would be to keep the results you want to re-use
within an array:

  require "mysql"
  db =3D Mysql.connect('localhost', 'root', '', 'test')

  items =3D db.query('SELECT * FROM items')
  tag_result =3D db.query('SELECT * FROM tags')
  tags =3D []
  tag_result.each_hash { |t| tags << t }

  items.each_hash do |item|
     puts item["title"]
     tags.each do |tag|
        puts tag["name"]
     end
  end

  puts tag_result.num_rows
  puts items.num_rows

Hope this helps.

On Mon, 2010-11-15 at 03:36 +0900, Andy Tolle wrote:
> botp wrote in post #961345:
> > On Sun, Nov 14, 2010 at 5:55 PM, Andy Tolle <durexlw.register / gmail.com=
>
> > wrote:
> >> items.each_hash do |item|
> >>  puts item["title"]
> >>  tags.each_hash do |tag|
> >
> > at this point, i'd be wary.  the iterator may not "rewind"
>=20
> Can you say something about how an iterator can not "rewind"? Do you=20
> mean I can't do nested iterators in ruby?
>=20


--=-NClKFSDOfPQG/S1zu9N+
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQIcBAABAgAGBQJM4PTtAAoJEIQdQGZOjo8200gP/2WP16ZaBsMYnwyeXm9aJKie
ZpW8LQQWc676R2HuXrl6ousOufJawC/5Dc9KN7uz83XMoE4CVSqWFHdBXSH7/fOd
d0mJrPCfr8l1OK8iszQD1aHqP7z+HyknMA3xbeuXD82C3ugslcaOHx0ntZBxm/cW
9/DCgRtIOOjaX7mN3IPQzyCnLwR/CrzGbl1tfrlst38ELkP4GCQgLiBEphW0xQBy
C4CgQfDN0sLf4tiBjXLDda8It3uigGqImljbmXsamd5BfnJPWJxqSDhWuJJgd9pd
Xb76wrKSEYxVdeHMIpQHfCv29bLEQFMvt/EJzbrin5U/uSDzRx2eD+YObKYZCLU8
jxTQ3Y3N5XrjbbGsML2QhbbJi/U9oUkrreY7uAjfwmjHXvmiAjeW0xgIIy06eKZs
8S/5PZQbiYScFy5xlD/RuuT0yY6L4HGkxqzosJfBOYMPXDw++MybV7uWeMr9Ndju
tqIYBkM1rLB0lND9bw2eH8kUEESfsz9RQ/IT6QJV2o0cSDmfYDoPTpugRDftWREG
maIacVtC5PmTGqtXhHCyTwcOUcECf3GnPmavVpIp6fIzxfpxzAWIdJsuHeORH4j6
12in3h3Rddi30fyKSLldIwZ2tW0uKq/mpe/rhb1+B10/eagrjB6MDe6drbLAY/h5
501AjJR7kTNE/Zjbjgym
=O6CT
-----END PGP SIGNATURE-----

--=-NClKFSDOfPQG/S1zu9N+--