From: AliasX Neo Date: 2006-11-21T12:15:37+09:00 Subject: Bug in ruby? Well, I've spent the last hour or so debugging one of the stupidest errors I have encountered with Ruby. Let's see my code first: [code]def parse(string, starting, ending) istart = string.index(starting) + starting.length iend = string.index(ending, istart) return string.slice(istart, iend - istart) end[/code] This function is called about 13 times in my entire script. It breaks on the last one with this error: undefined method `+' for nil:NilClass Now, I have debugged the living hell out of this application. It's breaking on the first line, stating that starting.length is a nil object and that it can't perform a + operator in a nil object. The string that's getting passed into starting is: buy_item.phtml? I debugged the application and put a mark on the first line to examine it in the following code: [code]def parse(string, starting, ending) length = starting.length istart = string.index(starting) + length iend = string.index(ending, istart) return string.slice(istart, iend - istart) end[/code] And the debugger said that length was an int with the value of 15. Guess what still happened? Got the exact same error with the + operator on a nil object. Except that completely contradicts the fact that it's not nil but it's an int with the value of 15. I have spent the last hour trying hundreds of different forms of this code and am getting the same exact error every time. I've come to the conclusion that this must be some kind of bug in Ruby, I can not pull on piece of logical evidence out of this. So my last resort is you guru's here, what am I doing wrong? Is there some kind of magical law I broke? This application needs to get done tonight, and I really can't afford anymore time on this tiny little bug. Thanks in advanced. ~ Alias -- Posted via http://www.ruby-forum.com/.