From: RichardOnRails Date: 2011-05-12T10:11:01+09:00 Subject: Re: Scope problem (?) in implementing Design Patterns in Ruby On May 11, 2:37 pm, David Jacobs wrote: > [Note:  parts of this message were removed to make it a legal post.] > > One more suggestion: if you're going to build a hierarchy, might as well > work the parent as much as possible. My final implementation would probably > look something like this: > > http://www.pastie.org/1889969 > > > > > > > > On Wed, May 11, 2011 at 1:51 PM, David Jacobs wrote: > > I think the second link points to the wrong pastie. > > > I can see a couple of problems with the code, first of which is that you > > are setting up Expression.new to require an argument but not passing it an > > argument when you call All_basic.new, etc. > > > More than design patterns (which I think are a little much here), I would > > suggest looking into Ruby's higher order functions like reduce and map. They > > make your code a lot simpler. This is an alternate implementation I did. Let > > me know what you think: > > >http://www.pastie.org/1889838 > > > On Wed, May 11, 2011 at 1:20 PM, RichardOnRails < > > RichardDummyMailbox58...@uscomputergurus.com> wrote: > > >> Hi, > > >> I'm hoping that employing "Design Patterns in Ruby" will lead to less > >> coding errors and more easily maintained code.  I'm stuck with the Not > >> pattern in the File Finding pattern in Chapter 15. > > >> I've posted my code and output inhttp://www.pastie.org/1889586and > >>http://www.pastie.org/188968, respectively.  Any idea about the cause > >> of the reported syntax error? > > >> Thanks in Advance, > >> Richard Hi David, Assuming I'm responding to the correct you version works perfectly, as evidenced by results below gotten after I decorated your code with puts versions. The Design Patterns author, Russ Olson, is aims to support a neat DSL to support file search with arbitrary logical combinations of the fundamental search elements ... which is my adopted goal. So I've got to master his approach to implementing this search language before I can really weigh approaches. 7stud has responded with the key thing I saw but couldn't figure out how to address the problem, so I've got to follow up on that now. Thanks for very detailed responses in intrinsic Ruby education. Best wishes, Richard ======== Output ========== >ruby DavesTempFilesDirs_2.rb files.select &all ========== AlternativeFileSearch.rb DavesTempFilesDirs_1.rb DavesTempFilesDirs_2.rb FindFilesDirs-01.rb FindFilesDirs-02.rb FindFilesDirs.rb TempFindFilesDirs.rb TestDoc@.txt TestFolder TestFolder/TestDoc.txt files.select &filename(/-01/)) ========== FindFilesDirs-01.rb files.select &writable ========== AlternativeFileSearch.rb DavesTempFilesDirs_1.rb DavesTempFilesDirs_2.rb FindFilesDirs-01.rb FindFilesDirs-02.rb FindFilesDirs.rb TempFindFilesDirs.rb TestFolder/TestDoc.txt files.select &_not(writable) ========== TestDoc@.txt TestFolder >Exit code: 0