Hi --
On Thu, 10 Apr 2008, Mario Ruiz wrote:
> But not in this case:
>
> $globvar=Array.new()
> myHash=Hash.new()
> myHash["oneValue"]="mygenericvalue"
> $globvar[0]=myHash
>
> localvar=$globvar.dup
>
> localvar[0]["oneValue"]="mylocalvalue"
>
> puts $globvar
Try this:
irb(main):001:0> a = []
=> []
irb(main):002:0> h = {}
=> {}
irb(main):003:0> h["one"] = "generic"
=> "generic"
irb(main):004:0> a[0] = h
=> {"one"=>"generic"}
irb(main):005:0> l = Marshal.load(Marshal.dump(a))
=> [{"one"=>"generic"}]
irb(main):006:0> l[0]["one"] = "local"
=> "local"
irb(main):007:0> a
=> [{"one"=>"generic"}]
(using globals if you absolutely must... but that's another story
David
--
Rails training from David A. Black and Ruby Power and Light:
ADVANCING WITH RAILS April 14-17 New York City
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
See
http://www.rubypal.com for details and updates!