From: Robert Dober Date: 2006-11-21T20:24:45+09:00 Subject: Re: Bug in ruby? ------=_Part_46745_11361131.1164108283675 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 11/21/06, Justin Collins wrote: > > AliasX Neo wrote: > > Well, I've spent the last hour or so debugging one of the stupidest > > errors I have encountered with Ruby. > > > > > > > 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. > > > > + is being called on string.index(starting) not length. I'd check to > make sure you aren't getting nil from that: which is expected behavior http://www.ruby-doc.org/core/classes/String.html#M000805 cheers Robert def parse(string, starting, ending) > p string.index(starting) > istart = string.index(starting) + length > iend = string.index(ending, istart) > return string.slice(istart, iend - istart) > end > > Hope that helps. > > -Justin > > -- The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man. - George Bernard Shaw ------=_Part_46745_11361131.1164108283675--