Class: TTFunk::OneBasedArray
- Inherits:
-
Object
- Object
- TTFunk::OneBasedArray
- Includes:
- Enumerable
- Defined in:
- lib/ttfunk/one_based_array.rb
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(size = 0) ⇒ OneBasedArray
constructor
A new instance of OneBasedArray.
- #size ⇒ Object
- #to_ary ⇒ Object
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 |
#size ⇒ Object
20 21 22 |
# File 'lib/ttfunk/one_based_array.rb', line 20 def size entries.size end |
#to_ary ⇒ Object
24 25 26 |
# File 'lib/ttfunk/one_based_array.rb', line 24 def to_ary entries end |