Class: AddArray

Inherits:
LazyArray show all
Defined in:
lib/lazzay.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#leftObject

Returns the value of attribute left.



65
66
67
# File 'lib/lazzay.rb', line 65

def left
  @left
end

#rightObject

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_sObject



86
87
88
# File 'lib/lazzay.rb', line 86

def to_s
    "#{@left} + #{@right}"
end