Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

ruby - To use self. or not.. in Rails

I've been coding in Ruby for sometime now, but I don't understand when to use:

def self.METHOD_NAME
end

or just:

def METHOD_NAME
end

In any Rails model. Is "self" a modifier like private in Java? When should I use it and when not?. Thanks a ton.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
def self.method_name
end

defines a class method.

def method_name
end

defines an instance method.

This is a pretty good post on it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...