This is not specific for Rails - I am just using Rails as an example.
I have a model in Rails:
class Item < ActiveRecord::Base
def hello
puts "Hello, #{self.name}"
end
end
(Let's assume that the Item
model (class) has a method called name
.) When do I need to use self.name
and when can I just use name
(e.g., #{name}
)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…