class Module
def thread_mattr_accessor(*syms, &blk)
Current.new.user = "DHH" # => NoMethodError
end
mattr_accessor :user, instance_accessor: false
class Current
Or pass instance_accessor: false, to opt out both instance methods.
Current.new.user # => NoMethodError
Current.new.user = "DHH" # => NoMethodError
end
thread_mattr_accessor :user, instance_writer: false, instance_reader: false
class Current
To opt out of the instance reader method, pass instance_reader: false.
To opt out of the instance writer method, pass instance_writer: false.
Account.user # => "DHH"
Customer.user # => "Rafael"
Customer.user = "Rafael"
end
class Customer < Account
is not changed.
Similarly, if the parent class changes the value, the value of subclasses
If a subclass changes the value, the parent class' value is not changed.
Account.new.user # => "DHH"
Account.user # => "DHH"
Account.user = "DHH"
end
thread_mattr_accessor :user
class Account
Defines both class and instance accessors for class attributes.
def thread_mattr_accessor(*syms, &blk) thread_mattr_reader(*syms, &blk) thread_mattr_writer(*syms, &blk) end