Class: Doubleshot::ReadonlyCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/doubleshot/readonly_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ ReadonlyCollection

Returns a new instance of ReadonlyCollection.



6
7
8
9
10
11
# File 'lib/doubleshot/readonly_collection.rb', line 6

def initialize(collection)
  unless collection.is_a? Enumerable
    raise ArgumentError.new("+collection+ must be an Enumerable")
  end
  @collection = collection
end

Instance Method Details

#+(other) ⇒ Object



31
32
33
# File 'lib/doubleshot/readonly_collection.rb', line 31

def +(other)
  ReadonlyCollection.new(entries + other.entries)
end

#eachObject



13
14
15
# File 'lib/doubleshot/readonly_collection.rb', line 13

def each
  @collection.each { |entry| yield entry }
end

#empty?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/doubleshot/readonly_collection.rb', line 22

def empty?
  entries.empty?
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


26
27
28
# File 'lib/doubleshot/readonly_collection.rb', line 26

def eql?(other)
  other.is_a?(self.class) && entries == other.entries
end

#sizeObject Also known as: length



17
18
19
# File 'lib/doubleshot/readonly_collection.rb', line 17

def size
  entries.size
end