On Nov 5, 1:53=A0am, Jason Lillywhite <jason.lillywh... / gmail.com>
wrote:
> how would I iterate over a hash, such as
>
> x =3D { 'a' =3D> "hi", 'b' =3D> nil, 'c' =3D> "do"}

  x.each{ |k,v| x[k] =3D 'foo' unless v }

However, it is not always sane to alter something while you are
iterating over it. So,

  h =3D {}
  x.each{ |k,v| h[k] =3D v.nil? ? v : 'foo' }
  x.replace(h)

Or use Facets Enumerable#mash (alias #graph)

  require 'facets/enumerable/mash'

  x =3D x.mash{ |k,v| [k, v.nil? ? v : 'foo'] }

http://facets.rubyforge.org/doc/api/core/classes/Enumerable.html#M000429

7.