B
Belorion
I want a Hash of Hashes. Furthermore, I want it so that if a key for
the first has does not exist, the default value is a new hash. It's
simple enough to do a has_key? on a hash to see if it already exists,
but it seems like there might be a trick to it that I'm not aware of.
So, instead of
foo =3D Hash.new
mylist.each do |ii|
anotherlist.each do |jj|
if foo.has_key?( ii )
foo[ii][jj] =3D "hello world"
else
foo[ii] =3D { jj =3D> "hello world" }
end
end
end
I can do:
mylist.each do |ii|
anotherlist.each do |jj|
foo[ii][jj] =3D "hello world"
end
end
Any suggestions?
the first has does not exist, the default value is a new hash. It's
simple enough to do a has_key? on a hash to see if it already exists,
but it seems like there might be a trick to it that I'm not aware of.
So, instead of
foo =3D Hash.new
mylist.each do |ii|
anotherlist.each do |jj|
if foo.has_key?( ii )
foo[ii][jj] =3D "hello world"
else
foo[ii] =3D { jj =3D> "hello world" }
end
end
end
I can do:
mylist.each do |ii|
anotherlist.each do |jj|
foo[ii][jj] =3D "hello world"
end
end
Any suggestions?