Please consider the following snippet of code:
class Parent
def self.parent_greeting
return ‘Hello, from the Parent class.’
end
end
class Child < Parent
def self.child_greeting()
return ‘Hello, from Child class.’
end
def get_greeting()
puts(self.class.child_greeting())
puts(Parent.parent_greeting())
end
end
If I instantiate the Child class into my_greeting, then:
my_greeting.class.parent_greeting() => Hello, from the Parent class.
and
my_greeting.class.child_greeting() => Hello, from Child class.
My question is: What are these ‘class’ methods that show up in my
method calls to the object and in the get greeting method?
I have a hunch that the question is answered in the ‘Disambiguation’
section of Self in Ruby | Jimmy Cuadra; but, I wasn’t
able to understand it. Is the answer to my question something that I’m
going to be able to grasp; or, will I need to wait until my skills
improve?
Thanks for any input.
... doug