Calling a class method with self. doesn't work?

Hey guys

This may be a very beginner's question, but I just don't get it. This
works:

  module MyModule
    class MyClass
      def file_colon_line(*arg)
        MyModule::MyClass::textmate_colon_line(old_file_colon_line)
      end

      def self.textmate_colon_line(file_colon_line)
        # ...
      end
    end
  end
end

But I'd rather just use self when calling text_mate_colon_line like
this:

self::textmate_colon_line(old_file_colon_line)

But this doesn't work (method not found). What's the right way to do it?

Thanks,
Josh

···

--
Posted via http://www.ruby-forum.com/.

`self` always points current scope. so, to call class method from the
instance method, use `self.class.method_name`:

  module MyModule
    class MyClass
      def file_colon_line(*arg)
        self.class.textmate_colon_line(old_file_colon_line)
      end

      def self.textmate_colon_line(file_colon_line)
        # ...
      end
    end
  end

···

On Mon, 9 Jul 2012 00:28:41 +0900 Joshua Muheim <lists@ruby-forum.com> wrote:

This may be a very beginner's question, but I just don't get it. This
works:

  module MyModule
    class MyClass
      def file_colon_line(*arg)
        MyModule::MyClass::textmate_colon_line(old_file_colon_line)
      end

      def self.textmate_colon_line(file_colon_line)
        # ...
      end
    end
  end
end

But I'd rather just use self when calling text_mate_colon_line like
this:

self::textmate_colon_line(old_file_colon_line)

But this doesn't work (method not found). What's the right way to do
it?

--
Sincerely yours,
Aleksey V. Zapparov A.K.A. ixti
FSF Member #7118
Mobile Phone: +34 677 990 688
Homepage: http://www.ixti.net
JID: zapparov@jabber.ru

*Origin: Happy Hacking!

Thanks a lot. :slight_smile:

···

--
Posted via http://www.ruby-forum.com/.