Module: RMExtensions::ObjectExtensions::Accessors
- Defined in:
- lib/motion/accessors.rb
Instance Method Summary collapse
-
#rmext_weak_attr_accessor(*attrs) ⇒ Object
creates an
attr_accessor
like behavior, but the objects are stored with a WeakRef.
Instance Method Details
#rmext_weak_attr_accessor(*attrs) ⇒ Object
creates an attr_accessor
like behavior, but the objects are stored with a WeakRef. does not conform to KVO like attr_accessor does.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/motion/accessors.rb', line 10 def rmext_weak_attr_accessor(*attrs) attrs.each do |attr| define_method(attr) do instance_variable_get("@#{attr}") end define_method("#{attr}=") do |val| instance_variable_set("@#{attr}", WeakRef.new(val)) val end end end |