On Fri, 10 Feb 2006, David Vallner wrote:

> D??a ??tvrtok 09 Február 2006 17:51 ara.t.howard / noaa.gov napísal:
>>> target_f += { source_f ? source_f : 0.00 }
>>
>>    target_f += source_f.to_f
>>
>
> I'd have used:
>
> 	target_f += source_f || 0.0
>
> myself, but after hacking at irb a bit, ara's method seems somewhat sexier
> than that rather standard Ruby idiom. A nice perk is that it won't bug out on
> when the database returns the data as a String.

hmmm.  if that's the case (possible string) i'd use

   target_f += Float(source_f)

since

   harp:~ > ruby -r yaml -e'  target_f = 40.0;  y target_f += "junk".to_f  '
   --- 40.0

and

   harp:~ > ruby -r yaml -e'  target_f = 40.0;  y target_f += Float("junk")  '
   -e:1:in `Float': invalid value for Float(): "junk" (ArgumentError)
           from -e:1

but

   harp:~ > ruby -r yaml -e'  target_f = 40.0;  y target_f += Float("2")  '
   --- 42.0

cheers.

-a

-- 
happiness is not something ready-made.  it comes from your own actions.
- h.h. the 14th dali lama