To use self. or not.. in Rails

后端 未结 6 551
长情又很酷
长情又很酷 2020-11-30 21:29

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 METH         


        
6条回答
  •  死守一世寂寞
    2020-11-30 22:09

    self is like the this keyword in Java. It's a reference to the current object instance. If your model code performs an operation on the current object, then you'd probably need a function without self.method_name specifier.

提交回复
热议问题