Why I always write stupid things ? See the effect of attr_accessor with
private variable
pigeon% cat b.rb
#!./ruby
class A
attr_accessor :_n
def initialize
@a = 12
@_m = [1,2]
@_n = [3,4]
end
def a
puts "a : #{@a.inspect} - _m : #{@_m.inspect} - _n : #{@_n.inspect}"
end
end
class B < A
attr_accessor :_m
def initialize
@_m = [2,4]
@_n = 6
super
end
def a
puts "a : #{@a.inspect} - _m : #{@_m.inspect} - _n : #{@_n.inspect}"
super
end
end
b = B.new
b.a
b._m = 24
b._n = 36
b.a
pigeon%
pigeon% b.rb
a : 12 - _m : [2, 4] - _n : 6
a : 12 - _m : [1, 2] - _n : [3, 4]
a : 12 - _m : 24 - _n : 6
a : 12 - _m : [1, 2] - _n : 36
pigeon%
Guy Decoux