Class: AddArray
Instance Attribute Summary collapse
-
#left ⇒ Object
Returns the value of attribute left.
-
#right ⇒ Object
Returns the value of attribute right.
Instance Method Summary collapse
- #[](k) ⇒ Object
-
#initialize(left = [], right = []) ⇒ AddArray
constructor
A new instance of AddArray.
- #to_s ⇒ Object
Methods inherited from LazyArray
Methods inherited from Array
Constructor Details
#initialize(left = [], right = []) ⇒ AddArray
Returns a new instance of AddArray.
67 68 69 70 71 72 73 74 75 |
# File 'lib/lazzay.rb', line 67 def initialize(left=[], right=[]) <<~DOC Arguments ------ left: left side of + right: right side of + DOC @left, @right = left, right end |
Instance Attribute Details
#left ⇒ Object
Returns the value of attribute left.
65 66 67 |
# File 'lib/lazzay.rb', line 65 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
65 66 67 |
# File 'lib/lazzay.rb', line 65 def right @right end |
Instance Method Details
#[](k) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/lazzay.rb', line 77 def [](k) l = @left.length if k < l return @left[k] else return @right[k - l] end end |
#to_s ⇒ Object
86 87 88 |
# File 'lib/lazzay.rb', line 86 def to_s "#{@left} + #{@right}" end |