Class: Primitive::Array
- Inherits:
-
Object
- Object
- Primitive::Array
- Defined in:
- lib/primitive_array.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #[]=(index, element) ⇒ Object
-
#initialize(length) ⇒ Array
constructor
A new instance of Array.
Constructor Details
#initialize(length) ⇒ Array
Returns a new instance of Array.
4 5 6 7 |
# File 'lib/primitive_array.rb', line 4 def initialize(length) @length = length @storage = [] end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
3 4 5 |
# File 'lib/primitive_array.rb', line 3 def length @length end |
Instance Method Details
#[](index) ⇒ Object
14 15 16 17 |
# File 'lib/primitive_array.rb', line 14 def [](index) raise ArgumentError, 'Attempted to access an out-of-bounds element' unless index < @length @storage[index] end |
#[]=(index, element) ⇒ Object
9 10 11 12 |
# File 'lib/primitive_array.rb', line 9 def []=(index, element) raise ArgumentError, 'Attempted to access an out-of-bounds element' unless index < @length @storage[index] = element end |