On May 13, 10:46=A0am, David Jacobs <develo... / wit.io> wrote:
> [Note: =A0parts of this message were removed to make it a legal post.]
>
> Hi Richard,
>
> The & has to be adjacent to "all" or "filename" to act as expected. The &
> can mean one of two related things when you pass it to a method:
>
> 1. It can mean "pass the lambda expression that this variable points to i=
nto
> a block". That makes the following to snippets equivalent:
>
> # Snippet 1
> filter_function =3D lambda {|x| x =3D=3D 2 }
> [1, 2, 3, 4, 2].select &filter_function
>
> # Snippet 2
> [1, 2, 3, 4, 2].select {|x| x =3D=3D 2 }
>
> 2. It can mean "pass the instance method named by a symbol, and treat it =
as
> a block".
>
> That makes these two equivalent:
>
> # Snippet 1
> [1, 2, 3, 4, 2].select {|x| x.even? }
>
> # Snippet 2
> [1, 2, 3, 4, 2].select(&:even?)
>
> So what my code is doing is calling the all method, for example, and that
> method's sole job is to return a lambda that can then be passed in per th=
e
> above. You don't have to wrap the lambda in a method like I did. You coul=
d
> also just say:
>
> all =3D lambda {|x| x }
>
> I hope that makes things a little clearer!
>
> Cheers,
> David
> On Fri, May 13, 2011 at 3:31 AM, RichardOnRails <
>
>
>
>
>
>
>
> RichardDummyMailbox58... / uscomputergurus.com> wrote:
> > Hi Dave,
>
> > I checked out your Version 2. =A0Added puts stuff and restriction to
> > names of files, which should probably be another one of your methods
> > instead of my hard-coding.
> > Expanded code:http://www.pastie.org/1895917
> > Output:http://www.pastie.org/1895932
>
> > I have only one question: I put a space between the & and the method
> > following it; the code broke. =A0Is the construct you used documented o=
n-
> > line somewhere? =A0I've peeked at lambda documentation so I've got the
> > drift but I haven't used it in any of my code so far.
>
> > I copied your memo on the approach and plan to review it and use/
> > expand your code after I finish getting Russ Olson's code working or
> > giving up on it. =A0To his credit, =A0he posted his code on-line so I c=
an
> > avoid typos and he included an apparently thorough set of unit tests.
> > So I've got a lot of studying to do.
>
> > Again, =A0thanks for your guidance and great ideas,
> > Richard

Hi again, Dave,

> I hope that makes things a little clearer!

Crystal! as Kaffee said to Col. Jessep during their Gitmo meeting (A
Few Good Men)

Thanks for illuminating another area of Ruby where my proficiency
needs enhancement :-)

Best,
Richard