method
thread_mattr_accessor
v6.1.3.1 -
Show latest stable
-
0 notes -
Class: Module
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (-2)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (28)
- 7.1.3.2 (38)
- 7.1.3.4 (0)
- What's this?
thread_mattr_accessor(*syms, instance_reader: true, instance_writer: true, instance_accessor: true, default: nil)
public
Defines both class and instance accessors for class attributes.
class Account thread_mattr_accessor :user end Account.user = "DHH" Account.user # => "DHH" Account.new.user # => "DHH"
If a subclass changes the value, the parent class’ value is not changed. Similarly, if the parent class changes the value, the value of subclasses is not changed.
class Customer < Account end Customer.user = "Rafael" Customer.user # => "Rafael" Account.user # => "DHH"
To omit the instance writer method, pass instance_writer: false. To omit the instance reader method, pass instance_reader: false.
class Current thread_mattr_accessor :user, instance_writer: false, instance_reader: false end Current.new.user = "DHH" # => NoMethodError Current.new.user # => NoMethodError
Or pass instance_accessor: false, to omit both instance methods.
class Current thread_mattr_accessor :user, instance_accessor: false end Current.new.user = "DHH" # => NoMethodError Current.new.user # => NoMethodError