开发者

Difference between these two attr_reader?

开发者 https://www.devze.com 2023-01-22 03:21 出处:网络
class CustomerClass < ActiveRecord class << self attr_reader :lov end at开发者_Python百科tr_reader :lov1
class CustomerClass < ActiveRecord
   class << self
     attr_reader :lov
   end
   at开发者_Python百科tr_reader :lov1
end

What is the diffrence between attr_reader lov and lov1 ?


The difference is that :lov will be a class-level accessor, while :lov1 is instance-level.

So, you can only access lov1 from an instance:

customer = CustomerClass.new
lov1 = customer.lov1

While CustomerClass.lov1 wouldn't work, but CustomerClass.lov would.

0

精彩评论

暂无评论...
验证码 换一张
取 消