Class: Doubleshot::ReadonlyCollection
- Includes:
- Enumerable
- Defined in:
- lib/doubleshot/readonly_collection.rb
Instance Method Summary collapse
- #+(other) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(collection) ⇒ ReadonlyCollection
constructor
A new instance of ReadonlyCollection.
- #size ⇒ Object (also: #length)
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 |
#each ⇒ Object
13 14 15 |
# File 'lib/doubleshot/readonly_collection.rb', line 13 def each @collection.each { |entry| yield entry } end |
#empty? ⇒ Boolean
22 23 24 |
# File 'lib/doubleshot/readonly_collection.rb', line 22 def empty? entries.empty? end |
#eql?(other) ⇒ Boolean Also known as: ==
26 27 28 |
# File 'lib/doubleshot/readonly_collection.rb', line 26 def eql?(other) other.is_a?(self.class) && entries == other.entries end |
#size ⇒ Object Also known as: length
17 18 19 |
# File 'lib/doubleshot/readonly_collection.rb', line 17 def size entries.size end |