class TTFunk::OneBasedArray
Array with indexing starting at 1.
Attributes
Public Class Methods
Source
# File lib/ttfunk/one_based_array.rb, line 12 def initialize(size = 0) @entries = Array.new(size) end
@overload initialize(size)
@param size [Integer] number of entries in this array
@overload initialize(entries)
@param entries [Array] an array to take entries from
Public Instance Methods
Source
# 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
Get element by index.
@param idx [Integer] @return [any, nil] @raise IndexError if index is 0
Source
# File lib/ttfunk/one_based_array.rb, line 48 def each(&block) entries.each(&block) end
Iterate over elements.
@yieldparam element [any] @return [void]
Source
# File lib/ttfunk/one_based_array.rb, line 33 def size entries.size end
Number of elements in this array.
@return [Integer]
Source
# File lib/ttfunk/one_based_array.rb, line 40 def to_ary entries end
Convert to native array.
@return [Array]