Qualcuno sa perchè gli array utilizzano la stessa area di memoria negli
assegnamenti multipli? Non apprezzo questo genere di diversità che a mio
avviso non fanno altro che generare confusione:
Esempio:
#String
irb(main):013:0> a=b=""
=> “”
irb(main):014:0> a
=> “”
irb(main):015:0> b
=> “”
irb(main):016:0> a=“a”
=> “a”
irb(main):017:0> a
=> “a”
irb(main):018:0> b
=> “”
irb(main):019:0> b=“b”
=> “b”
irb(main):020:0> a
=> “a”
irb(main):021:0> b
=> “b”
#Fixnum
irb(main):033:0> a=b=0
=> 0
irb(main):034:0> a
=> 0
irb(main):035:0> b
=> 0
irb(main):036:0> a=1
=> 1
irb(main):037:0> a
=> 1
irb(main):038:0> b
=> 0
#Array
irb(main):039:0> a = b = []
=> []
irb(main):040:0> a=b=[]
=> []
irb(main):041:0> a
=> []
irb(main):042:0> b
=> []
irb(main):043:0> a<<“a”
=> [“a”]
irb(main):044:0> a
=> [“a”]
irb(main):045:0> b
=> [“a”]
irb(main):046:0> b<<“b”
=> [“a”, “b”]
irb(main):047:0> a
=> [“a”, “b”]
irb(main):048:0> b
=> [“a”, “b”]
irb(main):049:0> a.push “aa”
=> [“a”, “b”, “aa”]
irb(main):050:0> a
=> [“a”, “b”, “aa”]
irb(main):051:0> b
=> [“a”, “b”, “aa”]
irb(main):052:0>