Hi --
On Sat, 28 Jun 2008, Justin To wrote:
> #--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
See Ara Howard's advice about using narray. Still -- I just wanted to
suggest one or two things to make this method more concise and clear.
One thing you could do is:
def eql_size?(tda)
lh=size.split('x')
rh=tda.size.split('x')
return lh[0] == rh[0] && lh[1] == rh[1]
end
In general, it's good to let the comparison methods, like ==, do their
thing, which is to produce true and false. There's usually no need to
store and test the results separately.
Moreover, in this particular case, I think you could just do:
def eql_size?(tda)
size == tda.size
end
David
--
Rails training from David A. Black and Ruby Power and Light:
ADVANCING WITH RAILS July 21-24 Edison, NJ
See
http://www.rubypal.com for details and updates!