Messi
Messi

Reputation: 97

What is difference between these two methods in Ruby?

What is difference between these two methods in Ruby?

class Mod   

      def doc(str)
          ...
      end

      def Mod::doc(aClass) 
          ...
      end
end

Upvotes: 2

Views: 69

Answers (1)

SlySherZ
SlySherZ

Reputation: 1661

Mod::doc()

is a class method, whereas

doc()

is an instance method. Here's an example of how to use both:

class Mod   
    def doc()
        puts 1
    end

    def Mod::doc() 
        puts 2
    end
end

a = Mod.new
a.doc   #=> 1
Mod.doc #=> 2

Here's a question that compares it with

self.doc()

Upvotes: 6

Related Questions