Sha256: 7f03b3bf0d2efd91a987abbb3f7e2998d47bbafae0f22abfc0ee7ceef89071fe

Contents?: true

Size: 660 Bytes

Versions: 4

Compression:

Stored size: 660 Bytes

Contents

module VirtualBox
  module Proxies
    # A relationship which can be described as a collection, which
    # is a set of items.
    class Collection < Array
      def initialize(parent)
        super()
        
        @parent = parent
      end
      
      def <<(item)
        item.added_to_relationship(@parent) if item.respond_to?(:added_to_relationship)
        push(item)
      end
      
      def clear
        each do |item|
          delete(item)
        end
      end
      
      def delete(item)
        return unless super
        item.removed_from_relationship(@parent) if item.respond_to?(:removed_from_relationship)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
virtualbox-0.4.1 lib/virtualbox/proxies/collection.rb
virtualbox-0.4.0 lib/virtualbox/proxies/collection.rb
virtualbox-0.3.0 lib/virtualbox/proxies/collection.rb
virtualbox-0.2.0 lib/virtualbox/proxies/collection.rb