Thursday, April 05, 2007
...which of course stands for "Ruby is not C or Java"
In the midst of programming sipXconfig I need to fix call resolver bug. I need to count 'setup' and 'end' for each call leg.
I write my test. I add 4 lines of code. I end up with something like this:
if @end_time.nil? || @end_time < cse.event_time
@end_time = cse.event_time
I run my test and Ruby complains:
Exception: undefined method `-@' for Thu May 17 19:30:00 UTC 1990:Time
To which I eloquently say: what???
Couple of moments later with Douglas looking over my shoulder:
Douglas: is @end_time even defined
Me: scrolling to the definition
Me: silence back
Desperate problems call for unusual measures. Let's print @end_time
Ruby move follows. And Ruby says: syntaxt error
Can you see it now?
It took us about 30 seconds since syntax error. Turns out
@refcount--is not how you decrement in Ruby;
@refcount -= 1is. Which we always knew. Well: kind of...