Forum: Ruby Regexp issues...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
907f29cb608004d2156d5ce88240f09b?d=identicon&s=25 Tim Mcd (zonbi)
on 2008-11-20 21:04
http://pastie.org/319919

On line 42, I get an error that there is no function '[]' for
nil:Nilclass... am I just missing something extremely obvious?
C40020a47c6b625af6422b5b1302abaf?d=identicon&s=25 Stefano Crocco (crocco)
on 2008-11-20 21:12
(Received via mailing list)
Alle Thursday 20 November 2008, Tim Mcd ha scritto:
> http://pastie.org/319919
>
> On line 42, I get an error that there is no function '[]' for
> nil:Nilclass... am I just missing something extremely obvious?

You get that error because Regexp#match returns nil if there's no match.
In
this case, test is set to nil and, obviously, won't have a [] method.

Stefano
7a561ec0875fcbbe3066ea8fe288ec77?d=identicon&s=25 Sebastian Hungerecker (Guest)
on 2008-11-20 21:13
(Received via mailing list)
Tim Mcd wrote:
> http://pastie.org/319919
>
> On line 42, I get an error that there is no function '[]' for
> nil:Nilclass... am I just missing something extremely obvious?

Your regex does not match the string, so the call to match returns nil.

HTH,
Sebastian
907f29cb608004d2156d5ce88240f09b?d=identicon&s=25 Tim Mcd (zonbi)
on 2008-11-20 21:53
Ah... hehe, thanks guys!
This topic is locked and can not be replied to.