Call parent constructor in ruby

advertisements

How can I call parents constructor ?

module C
    attr_accessor :c, :cc
    def initialization c, cc
        @c, @cc = c, cc
    end
end

class B
    attr_accessor :b, :bb
    def initialization b, bb
        @b, @bb = b, bb
    end
end

class A < B
    include C
    attr_accessor :a, :aa
    def initialization (a, b, c, aa, bb, cc)
        #call B::initialization - ?
        #call C::initialization - ?
        @a, @aa = a, aa
    end
end

Thanks.


First, your method should be initialize, not initialization. Then, you can use super to call the parent class method. As for calling C's initializer in A, for clarity, I'd recommend splitting the initialization stuff into a different function, then just calling that function directly. It's easy to implement, and clearer.