Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/array.rb

Instance Method Summary collapse

Instance Method Details

#rotate_until(&block) ⇒ Object

Raises:

  • (IndexError)


3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/ext/array.rb', line 3

def rotate_until &block
  return if block[]
  found = false
  length.times do
    push shift
    if block[]
      found = true
      break
    end
  end
  raise IndexError unless found
end

#rotate_until_first_equals(obj) ⇒ Object



16
17
18
# File 'lib/ext/array.rb', line 16

def rotate_until_first_equals obj
  rotate_until { at(0) == obj }
end

#slice_exists?(slice) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
# File 'lib/ext/array.rb', line 20

def slice_exists? slice
  start = slice.first
  len = slice.size
  each_with_index do |e, i|
    return true if e == start && self[i,len] == slice
  end
  false
end

#to_cObject



29
30
31
# File 'lib/ext/array.rb', line 29

def to_c
  Terraformer::Coordinate.from_array self
end