Class: Mother::Collection
- Inherits:
-
Object
- Object
- Mother::Collection
- Includes:
- Enumerable
- Defined in:
- lib/mother/collection.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#mother ⇒ Object
readonly
Returns the value of attribute mother.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each(&block) ⇒ Object
- #first ⇒ Object
-
#initialize(mother, argument) ⇒ Collection
constructor
A new instance of Collection.
- #last ⇒ Object
Constructor Details
#initialize(mother, argument) ⇒ Collection
Returns a new instance of Collection.
7 8 9 10 11 12 |
# File 'lib/mother/collection.rb', line 7 def initialize(mother, argument) mother.argument_failure! unless argument.is_a?(Array) @mother = mother @data = argument end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/mother/collection.rb', line 3 def data @data end |
#mother ⇒ Object (readonly)
Returns the value of attribute mother.
3 4 5 |
# File 'lib/mother/collection.rb', line 3 def mother @mother end |
Instance Method Details
#[](index) ⇒ Object
22 23 24 |
# File 'lib/mother/collection.rb', line 22 def [](index) mother.create data[index] end |
#each(&block) ⇒ Object
26 27 28 |
# File 'lib/mother/collection.rb', line 26 def each(&block) data.map { |i| mother.create i }.each(&block) end |
#first ⇒ Object
14 15 16 |
# File 'lib/mother/collection.rb', line 14 def first mother.create data.first end |
#last ⇒ Object
18 19 20 |
# File 'lib/mother/collection.rb', line 18 def last mother.create data.last end |