On May 25, 6:30=A0pm, David Jacobs <develo... / wit.io> wrote:
> Hi Richard,
>
> Glad the advice helped!
>
> Probably a more concise (and robust) way to get the full pathname of your=
 Dir[] results would be:
>
> full_name =3D File.expand_path(path)
>
> This has the advantage of expanding '~' to '/home/richard' (or whatever).
>
> If you add in higher order functions *here* (I'm just saying this to rein=
force the earlier concept along with the above method), you go from this:
>
> array =3D []
> Dir.chdir(dir) do
> Dir['**/*'].each do |path| =A0# Added each & block
> =A0full_name =3D File.join(dir, path)
> =A0array << path
> end
> end
> array
>
> To this:
>
> Dir.chdir(dir) do
> Dir['**/*'].map {|path| File.expand_path(path) }
> endOn Tuesday, 24 May 2011 at 11:35 pm, RichardOnRails wrote:
>
> On May 12, 9:56 pm, David Jacobs <develo... / wit.io> wrote:
>
>
>
>
>
>
>
>
>
> > > Second, look into higher order functions. They let you change code fr=
om this:
>
> > Hi Dave,
>
> > I just want to let you know your tutelage on this thread has not gone
> > in vain.
>
> > 1. I wanted to return a list (i.e. array) of filenames rather than
> > concatenated strings. Maybe parsing the concatenated strings would
> > have gotten me my lists, but I want the arrays to be the direct output
> > (in part just to see if I understood your code well enough to do it.)
>
> > 2. I wanted to do it by passing a search pattern to Filename.new and
> > a directory to the related expression.
>
> > These changes are displayed athttp://www.pastie.org/1969301
>
> > I'm continuing to work on embracing the higher-order methods you
> > advocated.
>
> > Best wishes,
> > Richard

Hi David,

Thanks for your additional improvement. Shrinking 8 lines down to 3
reduces the likelihood of error 62.5% I'd say.  I like those odds|

I'm presently going through David Black's treatise as fast as I can
internalize the stuff.  Specifically, I just found out the the number
of Enumerable methods went from 26 to 47 as I switched my WindowsXP-
Pro's PATH from Ruby 1.8.6 to 1.9.2.  I just ran into a minor problem
that I'm going to post on a separate thread because I don't want
presume to hang on your coat-tails.

Best wishes,
Richard