Class: Mother::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mother/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/mother/collection.rb', line 3

def data
  @data
end

#motherObject (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

#firstObject



14
15
16
# File 'lib/mother/collection.rb', line 14

def first
  mother.create data.first
end

#lastObject



18
19
20
# File 'lib/mother/collection.rb', line 18

def last
  mother.create data.last
end