Sha256: eb837b803244ce9d605ea41e10c6947d016e4a9fe5bb22143342cbf59386cd41

Contents?: true

Size: 642 Bytes

Versions: 22

Compression:

Stored size: 642 Bytes

Contents

module RMExtensions

  module ObjectExtensions

    module Accessors

      # creates an +attr_accessor+ like behavior, but the objects are
      # stored with a WeakRef.
      # does not conform to KVO like attr_accessor does.
      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

    end

  end

end
Object.send(:include, ::RMExtensions::ObjectExtensions::Accessors)

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rm-extensions-0.1.1 lib/motion/accessors.rb
rm-extensions-0.1.0 lib/motion/accessors.rb