Accessing Class Methods

Please consider the following snippet of code:

class Parent
def self.parent_greeting
return ‘Hello, from the Parent class.’
class Child < Parent
def self.child_greeting()
return ‘Hello, from Child class.’
def get_greeting()

If I instantiate the Child class into my_greeting, then:

my_greeting.class.parent_greeting() => Hello, from the Parent class.


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; 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

Thanks for any input.

     ... doug

Module or Class methods are simply methods which don’t need or belong to
a particular instance. In general they’ll be methods which don’t need to
reference the internal state of an object. The most commonly used (but
not commonly altered) Class method would

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