Dear Lazarus,

It's a little confusing at first. But I think you will get it easily.

# +++
# First
# +++

# How do I define an instance method?

class MyClass
  def my_instance_method
  end
end

my_object = MyClass.new

# The instance method defined on our class ...

MyClass.instance_methods.grep(/my/)
# => [:my_instance_method]

# ... is a method callable on an instance of the class

my_object.methods.grep(/my/)
# => [:my_instance_method]

# +++
# Second
# +++

# How do I define an instance method on my singleton class (of my class)?

class MyClass
  class << self
    def my_eigen_instance_method
    end
  end
end

eigen = MyClass.singleton_class

# The instance method defined on our eigen class ...

eigen.instance_methods.grep(/eigen/)
# => [:my_eigen_instance_method]

# ... is a method (singleton method) callable on the class itself

MyClass.methods.grep(/eigen/)
# => [:my_eigen_instance_method]

MyClass.singleton_methods.grep(/eigen/)
# => [:my_eigen_instance_method]

# +++

To the questions...

On Sun, Feb 9, 2014 at 7:14 PM, Lazarus Slifer <lists / ruby-forum.com> wrote:
> Hello guys. I'm new here and on Ruby, so bear with me on this one.
>
> I know that when we define a class method on a class, it's created a
> singleton class that gets the definition of that method, and from then
> on, that method is an instance method of that singleton class(i got this
> conclusion from tests, but i might be wrong, so feel free to correct
> me).

> My question is, how can i call a class method on a class X with
> X.classMethod if the method is defined on a singleton class as an
> instance method of that class(i am not asking how can i do it. It is
> what happens.).

The method lookup chain searches first for methods defined on its metaclass.

>  It confuses me even more, because i noticed(running some tests) that
> the singleton class of a class is not even hierarchically related to the
> class it comes from,

We could say that a class is an instance of its metaclass.
Or... the metaclass is "inserted" between MyClass and its class
(Class) in the method lookup chain.

> so, how is a class method call resolved to the
> singleton class?

(Same as above.)

> And more precisely: how is the class calling a method
> on a singleton class that is an instance method, without any instance.

MyClass is an object (instance) also even if its a class.
Or... in Ruby  the classes are also objects.

> I hope i did not confuse you.
>
> Thank you.
>
> --
> Posted via http://www.ruby-forum.com/.