Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/open-ship/gga4r/array_helper.rb

Instance Method Summary collapse

Instance Method Details

#each_pairObject

Yields given bloc using arrays items pair by pair. e.g. <code> [“a”,“b”,“c”,“d”].each_pair do |first, second|

puts second + " - " + second

end </code> will print: b - a c - d



15
16
17
18
19
20
# File 'lib/open-ship/gga4r/array_helper.rb', line 15

def each_pair
  num = self.size/2
  (0..num-1).collect do |index|
    yield self[index*2], self[(index*2)+1]
  end
end

#separate(position) ⇒ Object

Splits the array into two parts first from position 0 to “position” and second from position “position+1” to last position. Returns two new arrays.



26
27
28
# File 'lib/open-ship/gga4r/array_helper.rb', line 26

def separate(position)
 return self[0..position], self[position+1..-1]
end