Class: ActiveRecord::AttributeMethods::AttributeMethodCache
- Includes:
- Mutex_m
- Defined in:
- activerecord/lib/active_record/attribute_methods.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize ⇒ AttributeMethodCache
constructor
A new instance of AttributeMethodCache.
Constructor Details
#initialize ⇒ AttributeMethodCache
Returns a new instance of AttributeMethodCache.
34 35 36 37 38 |
# File 'activerecord/lib/active_record/attribute_methods.rb', line 34 def initialize super @module = Module.new @method_cache = {} end |
Instance Method Details
#[](name) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'activerecord/lib/active_record/attribute_methods.rb', line 40 def [](name) synchronize do @method_cache.fetch(name) { safe_name = name.unpack('h*').first temp_method = "__temp__#{safe_name}" ActiveRecord::AttributeMethods::AttrNames.set_name_cache safe_name, name @module.module_eval method_body(temp_method, safe_name), __FILE__, __LINE__ @method_cache[name] = @module.instance_method temp_method } end end |