Class: TTFunk::OneBasedArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ttfunk/one_based_array.rb

Instance Method Summary collapse

Constructor Details

#initialize(size = 0) ⇒ OneBasedArray

Returns a new instance of OneBasedArray.



7
8
9
# File 'lib/ttfunk/one_based_array.rb', line 7

def initialize(size = 0)
  @entries = Array.new(size)
end

Instance Method Details

#[](idx) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/ttfunk/one_based_array.rb', line 11

def [](idx)
  if idx.zero?
    raise IndexError,
      "index #{idx} was outside the bounds of the array"
  end

  entries[idx - 1]
end

#each(&block) ⇒ Object



28
29
30
# File 'lib/ttfunk/one_based_array.rb', line 28

def each(&block)
  entries.each(&block)
end

#sizeObject



20
21
22
# File 'lib/ttfunk/one_based_array.rb', line 20

def size
  entries.size
end

#to_aryObject



24
25
26
# File 'lib/ttfunk/one_based_array.rb', line 24

def to_ary
  entries
end