Robert Klemme
3/9/2009 4:47:00 PM
2009/3/9 Torli Birnbauer <aipir@sympatico.ca>:
> badboy wrote:
>> did you read my post? why should we use a construct with a block if
>> there are several methods to do this directly?
>
> Because the block way is the Ruby way, besides it's much more efficient
> it does open, read and close in one short command! Beside it its
> elegance it also has a pedagogical value, namely, it highlights and
> exposes the use of Ruby 1.9 usage of Symbol class to_proc strategy. So
> all I can say is: Matthias, excellent contribution to this thread, very
> good job.
Frankly, I believe you haven't properly read badboy's posting. I'll
show his code below.
> Perhaps only a comment that even reading multi-line file into a variable
> sometimes can be useful with:
>
> =A0guess =3D File.open("zorba.data", &:readlines)
>
> Clearly the old way in comparison to the the block is more like the
> spaghetti code!
Like these?
17:45:12 tmp$ cat >| x <<EOF
> 123
> 456
> EOF
17:45:23 tmp$ cat x
123
456
17:45:25 tmp$ allruby -e 'p File.read("x"), File.readlines("x")'
ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]
"123\n456\n"
["123\n", "456\n"]
ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-cygwin]
"123\n456\n"
["123\n", "456\n"]
17:45:55 tmp$
Very spaghetti indeed.
Cheers
robert
PS: This posting contains traces of irony. Please handle with care.
--=20
remember.guy do |as, often| as.you_can - without end