Initialization of class when inhereted

Hi!

class BaseClass
def BaseClass.initialization_for_derived_class
@var = do_something
end
end

class DerivedClass < BaseClass
end

I’d like to initialize @var in DerivedClass. Is there some way to run
initialization_for_derived_class when inheriting BaseClass?

Alexander Ponomarchuk wrote:

Hi!

class BaseClass
def BaseClass.initialization_for_derived_class
@var = do_something
end
end

class DerivedClass < BaseClass
end

I’d like to initialize @var in DerivedClass. Is there some way to run
initialization_for_derived_class when inheriting BaseClass?

Yes. ri Class#inherited

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs