Initialization of class when inhereted

  • Thread starter Alexander Ponomarchuk
  • Start date
A

Alexander Ponomarchuk

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?
 
B

Brian Candler

Alexander said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,939
Members
47,484
Latest member
JackRichard

Latest Threads

Top