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.
Tim M. (Guest)
on 2008-11-20 22: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?
Stefano C. (Guest)
on 2008-11-20 22:12
(Received via mailing list)
Alle Thursday 20 November 2008, Tim M. 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
Sebastian H. (Guest)
on 2008-11-20 22:13
(Received via mailing list)
Tim M. 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
Tim M. (Guest)
on 2008-11-20 22:53
Ah... hehe, thanks guys!
This topic is locked and can not be replied to.