Flowdock
method

thread_mattr_writer

Importance_1
v5.0.0.1 - Show latest stable - 0 notes - Class: Module
thread_mattr_writer(*syms) 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"

If you want to opt out 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.