S.E.A.N.I.C.U.S.

Tuesday, June 13, 2006

You learn something new everyday

I reaffirmed this morning my previous habit of using console-printing as a debugging method. In trying to ferret out the FlexTimes problem (see yesterday's post), I found that part of my logic was flawed in the write_attribute. Here's a snippet that doesn't work:
case column.klass # the AR column type
when Date
@attributes[attr_name] = Date.today.to_hash.update(value).to_date
when Time
@attributes[attr_name] = value.to_time
else
@attributes[attr_name] = value
end
Here's the replacement that does:
if column.klass == Date
@attributes[attr_name] = Date.today.to_hash.update(value).to_date
elsif column.klass == Time
@attributes[attr_name] = value.to_time
else
@attributes[attr_name] = value
end
Very subtle difference, but it makes me wonder if I'm not understanding Ruby's case statement correctly. Does it actually check for equality of the when argument to the case argument? Anyone who could elucidate this would receive my eternal gratitude.

Oh yes, and the bug(s) described in yesterday's posts are fixed. Go ahead and use 1.5... I know I will!