Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/module.rb

Instance Method Summary collapse

Instance Method Details

#tl_attr(name, writable = false) ⇒ Object



23
24
25
26
27
# File 'lib/core_ext/module.rb', line 23

def tl_attr(name, writable = false)
  tl_attr_reader(name)
  
  tl_attr_writer(name) if writable
end

#tl_attr_accessor(*names) ⇒ Object



2
3
4
5
# File 'lib/core_ext/module.rb', line 2

def tl_attr_accessor(*names)
  tl_attr_reader(*names)
  tl_attr_writer(*names)
end

#tl_attr_reader(*names) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/core_ext/module.rb', line 7

def tl_attr_reader(*names)
  names.each do |name|
    define_method(name) do
      Thread.current["#{self.class.name.downcase}_#{object_id}_#{name.to_s}"]
    end
  end
end

#tl_attr_writer(*names) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/core_ext/module.rb', line 15

def tl_attr_writer(*names)
  names.each do |name|
    define_method("#{name}=".to_sym) do |new_value|
      Thread.current["#{self.class.name.downcase}_#{object_id}_#{name.to_s}"] = new_value
    end
  end
end