On May 21, 2010, at 8:27 PM, tjg wrote:

Hi Kevin,

Nope, can't check for nil on the attribute since that calls the
attribute accessor causing recursion and an eventual segmentation
fault.

There's always

def instrument_no
  "%0.3f" % read_attribute(:instrument_no) rescue nil
end

(or rescue '0.000' - your call) which will ensure that the % can't cause problems.

Out of curiosity, is :instrument_no an actual float value? The above will cause problems if you try to do math with it (as it's returned as a string). If it's not something you'd expect to do math on, but just a "number with 3 digits after the decimal", I'd highly recommend you look into using a decimal type.

--Matt Jones

--
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to