Class: NBA::Collection
- Inherits:
-
Object
- Object
- NBA::Collection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/nba/collection.rb
Overview
Represents a collection of objects
Instance Attribute Summary collapse
-
#elements ⇒ Array
readonly
private
Returns the elements in the collection.
Instance Method Summary collapse
-
#each {|element| ... } ⇒ Enumerator, self
Iterates over the elements in the collection.
-
#empty? ⇒ Boolean
Returns true if the collection has no elements.
-
#first ⇒ Object?
Returns the first element in the collection.
-
#initialize(elements = []) ⇒ NBA::Collection
constructor
Initializes a new Collection.
-
#last ⇒ Object?
Returns the last element in the collection.
-
#size ⇒ Integer
(also: #length, #count)
Returns the number of elements in the collection.
Constructor Details
#initialize(elements = []) ⇒ NBA::Collection
Initializes a new Collection
71 72 73 |
# File 'lib/nba/collection.rb', line 71 def initialize(elements = []) @elements = elements end |
Instance Attribute Details
#elements ⇒ Array (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the elements in the collection
62 63 64 |
# File 'lib/nba/collection.rb', line 62 def elements @elements end |
Instance Method Details
#each {|element| ... } ⇒ Enumerator, self
Iterates over the elements in the collection
82 83 84 85 86 87 |
# File 'lib/nba/collection.rb', line 82 def each(&block) return enum_for unless block elements.each(&block) self end |
#empty? ⇒ Boolean
Returns true if the collection has no elements
|
|
# File 'lib/nba/collection.rb', line 18
|
#first ⇒ Object?
Returns the first element in the collection
|
|
# File 'lib/nba/collection.rb', line 25
|
#last ⇒ Object?
Returns the last element in the collection
|
|
# File 'lib/nba/collection.rb', line 32
|
#size ⇒ Integer Also known as: length, count
Returns the number of elements in the collection
|
|
# File 'lib/nba/collection.rb', line 11
|