lib/emittance/dispatcher/registration_collection_proxy.rb in emittance-0.1.0 vs lib/emittance/dispatcher/registration_collection_proxy.rb in emittance-0.1.1

- old
+ new

@@ -15,20 +15,43 @@ # @param args args passed to +Array#each+ # @param blk block passed to +Array#each+ # @return [RegistrationCollectionProxy] self def each(*args, &blk) - arrays = mappings.values.map(&:to_a) arrays.flatten.each(*args, &blk) self end # @return [Boolean] true if there are no registrations at all, false otherwise def empty? mappings.values.all?(&:empty?) end + # @return [Integer] the number of registrations that exist in the collection + def length + arrays.flatten.length + end + + alias size length + alias count length + + # @param idx [Integer] the index you wish to find + # @return the registration indexed at the specified index + def [](idx) + arrays.flatten[idx] + end + + # @return the registration at the first index + def first + self[0] + end + + # @return the registration at the last index + def last + self[-1] + end + # @return [RegistrationCollectionProxy] self def <<(item) mappings[lookup_term] << item self end @@ -40,8 +63,12 @@ end private attr_reader :lookup_term, :mappings + + def arrays + mappings.values.map(&:to_a) + end end end end