method
thread_mattr_reader
v5.1.7 -
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 (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)
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 # => nil Thread.current[:attr_Current_user] = "DHH" Current.user # => "DHH"
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
If you want to opt out of the creation of 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