From: James Harrison Date: 2010-08-02T22:54:04+09:00 Subject: Re: Iteration through File.file? misses entries for which File.file?(entry) == true If you're going to write an email and be wrong, be wrong on every point, that's what I was always taught and I'm sticking by it goddamit! On Aug 2, 2010, at 7:28 AM 8/2/10, Brian Candler wrote: > 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?) You're 100% correct. Total brainfart. > >> 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. In future, I'll have to stop myself whenever the thought "that mightn't be the right word" crops through my head. I figured it'd be close enough to get the idea across, but given that a symbol is actually a language construct I should've taken a few more seconds out. In either case, you've hit something that interests me. Conceptually, I'd understood that the difference between an @-prepended variable and a non-@-prepended variable is that the former is global to the object, so it's not impacted by the change in scope introduced by defining a method inside the object. So I figured that describing the @ character as changing the internal scope of a variable from local to global inside the object wouldn't be entirely missing the mark. But it's possible I'm missing something. Thanks for the clarifications and corrections, dude. Best James