G
gga
irb> a = [1,2]
=> [1, 2]
irb> a
=> [1, 2, 3, 4]
irb(main):082:0> a
=> [1, 2, 3, 4]
So far so good...
irb(main):082:0> def add(x)
irb(main):084:1> x += [5,6]
irb(main):085:1> end
irb(main):087:0> add(a)
=> [1, 2, 3, 4, 5, 6]
irb(main):088:0> a
=> [1, 2, 3, 4] ===>>> uh? am I not passing stuff by reference?
where is 5, 6?
irb(main):089:0> def add2(x)
irb(main):089:0> x << [5,6]
irb(main):089:0> end
irb(main):090:0> add2(a)
=> [1, 2, 3, 4, [5, 6]]
irb(main):091:0> a
=> [1, 2, 3, 4, [5, 6]] ==> seems logical, but then .... why +=
behaves differently?
=> [1, 2]
irb> a
=> [1, 2, 3, 4]
irb(main):082:0> a
=> [1, 2, 3, 4]
So far so good...
irb(main):082:0> def add(x)
irb(main):084:1> x += [5,6]
irb(main):085:1> end
irb(main):087:0> add(a)
=> [1, 2, 3, 4, 5, 6]
irb(main):088:0> a
=> [1, 2, 3, 4] ===>>> uh? am I not passing stuff by reference?
where is 5, 6?
irb(main):089:0> def add2(x)
irb(main):089:0> x << [5,6]
irb(main):089:0> end
irb(main):090:0> add2(a)
=> [1, 2, 3, 4, [5, 6]]
irb(main):091:0> a
=> [1, 2, 3, 4, [5, 6]] ==> seems logical, but then .... why +=
behaves differently?
ruby 1.8.2 (2004-12-25) [i686-linux]ruby -v