ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: Puzzled?
by Akchizar other posts by this author
Jun 30 2006 6:17PM messages near this date
Puzzled? | Re: [QUIZ] C-Style Ints (#85) - not a spoiler, a test harness
Regexp#match returns nil if it doesn't match anything. On the first  
run through your each statement, s is "foo", which doesn't match  
against your regex. That means m is nil, and so you get an error when  
trying to grab m[0].

On 1/07/2006, at 12:58 PM, Volkan Civelek wrote:

>  Hi,
>  I have a question...
> 
>  Why the below snippet,
> 
>  ["foo","bar","baz"].each do |s|
>      m = /^ba(.*?)$/.match(s)
>      puts m[0]
>  end
> 
>   gives the following error?
> 
>  test.rb:8: undefined method `[]' for nil:NilClass (NoMethodError)
> 
>  Regards,
>  Volkan
> 
Thread:
Volkan Civelek
Akchizar

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved