I want to leverage class methods on child classes in ruby, but those that rely on child instance variables are not working. I was told "don't use class variables! (@@)", so I'm not. How can I make class B
do what I want, namely print out "1"
?
class A
@a = "1"
def initialize
self.class.what_is_a
end
def self.what_is_a
p @a
end
end
class B < A
end
A.what_is_a
B.what_is_a
A.new
B.new
The output:
"1"
nil
"1"
nil
I'd like them all to be "1"
.