method

thread_mattr_writer

Importance_1
v7.1.3.4 - Show latest stable - 0 notes - Class: Module
thread_mattr_writer(*syms, instance_writer: true, instance_accessor: true) public

Defines a per-thread class attribute and creates a class and instance writer methods to allow assignment to the attribute.

module Current
  thread_mattr_writer :user
end

Current.user = "DHH"
Thread.current[:attr_Current_user] # => "DHH"

To omit the instance writer method, pass instance_writer: false or instance_accessor: false.

class Current
  thread_mattr_writer :user, instance_writer: false
end

Current.new.user = "DHH" # => NoMethodError
Show source
Register or log in to add new notes.