My question is: is there a way to find out these spots in my program, like a 
compiler do in Delphi/C.

e.g.:

def test(arr)
  arr.each do |a|
   ...
  end
end

in the above code, I will naturally assume arr is an array. Only after the 
program is in use (may be even a year later!), I suddenly got a report of 
error caused by "arr is nil".

In delphi, for example, such error is detected while compile, e.g. (a might 
not have been initialized).  I know Ruby works differently, but is there a 
way (or a project) exists, like a normal compiler, or something like FxCop 
for the C# language?

Thanks,
Shannon


>From: matt / tidbits.com (matt neuburg)
>Reply-To: ruby-talk / ruby-lang.org
>To: ruby-talk / ruby-lang.org (ruby-talk ML)
>Subject: Re: ruby programming best practice
>Date: Thu, 2 Nov 2006 02:25:22 +0900
>
>Shannon Fang <xrfang / hotmail.com> wrote:
>
> > As a dynamic language, Ruby is much more flexible and easier than other
> > language I use, for example, Delphi. However, there is a "intrinsic" 
>problem
> > in ruby programming -- a typical error I get again and again:
> >
> > private method `split' called for nil:NilClass
> >
> > The following statement:
> >
> > array.pop.split(',')
> >
> > will generate this error if array is empty.
>
>If my goal is that I just want skip the step if it can't be done, I like
>this kind of thing:
>
>  array.pop.split(',') if array.last
>
>If array itself could be nil then I have to add:
>
>  puts array.pop.split(',') if array and array.last
>
>m.
>--
>matt neuburg, phd = matt / tidbits.com, http://www.tidbits.com/matt/
>Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
>AppleScript - http://www.amazon.com/gp/product/0596102119
>Read TidBITS! It's free and smart. http://www.tidbits.com
>

_________________________________________________________________
Download the new Windows Live Toolbar, including Desktop search! 
http://toolbar.live.com/?mkt=en-gb