From: Brian Candler Date: 2010-08-02T22:28:00+09:00 Subject: Re: Iteration through File.file? misses entries for which File.file?(entry) == true James Harrison wrote: > The symbolic constant for truth is True, not true. That is incorrect, as 5 seconds with irb will show you. $ irb --simple-prompt >> true => true >> True NameError: uninitialized constant True from (irb):2 (You may have been thinking of TrueClass and FalseClass, perhaps?) > In either case, because File.file? returns either True or False, you can > drop the comparison: It returns true or false, but yes the comparison can be removed. > If this is truly a method in an object, though, bear in mind scoping > issues. pwdFiles is only available inside this method definition. When > you declare it in your intialize statement, prepend with a > scope-changing symbol. The most common in this case is @ > > def initialize > #will contain all file entries in the directory > @pwdFiles = [] > end @ is not a "scope changing symbol". @pwdFiles is an instance variable of the object, whereas pwdFiles is a local variable. They are completely different concepts. Since the OP wanted to return the value from the getFiles method, and not set any instance variables in the object, then a local variable is appropriate here. -- Posted via http://www.ruby-forum.com/.