I need to set multiple hashes, and I don't want to list one line at a time, for example,
a = Hash.new b = Hash.new
I am also a newbie that apart from Fixnums I could not do this
a = b = Hash.new
since both a and b will refer to the same object. I can do it
a, b, = Hash.new, Hash.new
If I had a group, it seemed to me that I could do it too
a, b = [Hash.new] * 2
this works for strings, but for hashes they all refer to the same object, despite the fact that
[Hash.new, Hash.new] == [Hash.new] * 2
and the previous one works.
See the sample code below for a single error message caused by a "propagation hash." Just curious why that is.
a, b, c = [String.new] * 3 a = "hi" puts "string broken" unless b == "" puts "not equivalent" unless [Hash.new, Hash.new, Hash.new] == [Hash.new] * 3 a, b, c = [Hash.new, Hash.new, Hash.new] a['hi'] = :test puts "normal hash broken" unless b == {} a, b, c = [Hash.new] * 3 a['hi'] = :test puts "multiplication hash broken" unless b == {}