J
Justin To
class Tda
def initialize(width=0, height=0)
if((width==0) && width<height)
raise NotImplementedError,
"\(#{width}\) width Tda cannot have a height."
else
@tda = Array.new(width).map!{ Array.new(height) }
end
end
def width?
return @tda.size
end
def height?
if(width?>0)
return @tda[0].size
else
return nil
end
end
#--Returns the dimensional size (x x y) as a string
def size
[email protected]
if(width?>0)
h = @tda[0].size
else
h = 0
end
return "#{w}x#{h}"
end
#--Returns true if both Tda's have equal widths and heights
def eql_size?(tda)
bool=false
lh=size.split('x')
rh=tda.size.split('x')
if(lh[0]==rh[0])
bool=true
end
if(lh[1]==rh[1])
bool=true
else
bool=false
end
return bool
end
end
This is what I've got so far, but I can't seem to figure out how to
write methods for: copying a Tda to another Tda, and indexing the Tda.
Thanks for the help!
def initialize(width=0, height=0)
if((width==0) && width<height)
raise NotImplementedError,
"\(#{width}\) width Tda cannot have a height."
else
@tda = Array.new(width).map!{ Array.new(height) }
end
end
def width?
return @tda.size
end
def height?
if(width?>0)
return @tda[0].size
else
return nil
end
end
#--Returns the dimensional size (x x y) as a string
def size
[email protected]
if(width?>0)
h = @tda[0].size
else
h = 0
end
return "#{w}x#{h}"
end
#--Returns true if both Tda's have equal widths and heights
def eql_size?(tda)
bool=false
lh=size.split('x')
rh=tda.size.split('x')
if(lh[0]==rh[0])
bool=true
end
if(lh[1]==rh[1])
bool=true
else
bool=false
end
return bool
end
end
This is what I've got so far, but I can't seem to figure out how to
write methods for: copying a Tda to another Tda, and indexing the Tda.
Thanks for the help!