method
thread_mattr_reader
Ruby on Rails latest stable (v7.1.3.2)
-
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 (3)
- 5.2.3 (0)
- 6.0.0 (-38)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (-1)
- 7.1.3.4 (0)
- What's this?
thread_mattr_reader(*syms, instance_reader: true, instance_accessor: true, default: nil)
public
Defines a per-thread class attribute and creates class and instance reader methods. The underlying per-thread class variable is set to nil, if it is not previously defined.
module Current thread_mattr_reader :user end Current.user = "DHH" Current.user # => "DHH" Thread.new { Current.user }.value # => nil
The attribute name must be a valid method name in Ruby.
module Foo thread_mattr_reader :"1_Badname" end # => NameError: invalid attribute name: 1_Badname
To omit the instance reader method, pass instance_reader: false or instance_accessor: false.
class Current thread_mattr_reader :user, instance_reader: false end Current.new.user # => NoMethodError