class TTFunk::OneBasedArray
Array with indexing starting at 1.
Attributes
entries[R]
Public Class Methods
new(size = 0)
click to toggle source
@overload initialize(size)
@param size [Integer] number of entries in this array
@overload initialize(entries)
@param entries [Array] an array to take entries from
# File lib/ttfunk/one_based_array.rb, line 12 def initialize(size = 0) @entries = Array.new(size) end
Public Instance Methods
[](idx)
click to toggle source
Get element by index.
@param idx [Integer] @return [any, nil] @raise IndexError if index is 0
# File lib/ttfunk/one_based_array.rb, line 21 def [](idx) if idx.zero? raise IndexError, "index #{idx} was outside the bounds of the array" end entries[idx - 1] end
each(&block)
click to toggle source
Iterate over elements.
@yieldparam element [any] @return [void]
# File lib/ttfunk/one_based_array.rb, line 48 def each(&block) entries.each(&block) end
size()
click to toggle source
Number of elements in this array.
@return [Integer]
# File lib/ttfunk/one_based_array.rb, line 33 def size entries.size end
to_ary()
click to toggle source
Convert to native array.
@return [Array]
# File lib/ttfunk/one_based_array.rb, line 40 def to_ary entries end