From: Matthew Smillie Date: 2006-06-08T22:50:30+09:00 Subject: Re: Easy question On Jun 8, 2006, at 14:20, Robert Mela wrote: > I want to maintain a list of two-dimensional points and store, at > list level, the min and max values for x and y. > The minx/maxx/miny/maxy should be updated as each point is pushed > onto the list. > > The following works, but it's probably not leveraging Ruby: > > > def add_point( p ) > @points.push(p) > if !@minx || @minx > p.x > @minx=p.x > end > if .... There's not a lot of changes you can make to something as simple as a conditional, actually. Even if you improve the aesthetics, there's little practical impact in re-writing simple conditionals. That said, you can compress each statement into a single line using the if/unless as a modifier (like Perl). I tend to prefer 'unless' in this case, but that's just me. @minx = p.x unless @minx and p.x > @minx @minx = p.x if !@minx or @minx > p.x matthew smillie.