Hi --

On Sat, 6 Jan 2007, Bryan Weatherly wrote:

> On 1/5/07, Jay Bornhoft <jbornhoft / gmail.com> wrote:
>> 
>> Btw, is there a way to get the same 'def' to process both the positive
>> and negative 'x' values?
>> 
>> 
> You could have it return an array, where the first element is the 1st
> solution and the second element is the 2nd solution:
>
> def quad(a,b,c)
> [   -b + ((b**2 - 4.0*a*c)/(2.0*a))**(0.5),  -b - ((b**2 - 4.0*a*c)/(2.0*a
> ))**(0.5) ]
> end

Or, if you don't want to type stuff twice:

def quad(a,b,c)
  [:+,:-].map {|sign| -b.send(sign, ((b**2 - 4*a*c)**(0.5))) / (a*2) }
end

:-)


David

-- 
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
    (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)