From: "林彰史" Date: 2012-12-14T00:54:11+09:00 Subject: Re: Enumerable#zip with File IO --047d7bf0d490cf076a04d0bdd9e8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks all, I have tried the same script with JRuby 1.7.0 also, and I got: 1: 111 2: Not only the second line but also the third line disappears. Replacing arrays with ranges did not change the output. I checked StringIO also and got the same. So, my conclusion is that Enumerable#zip can be applied to IO Enumerable object only once, as Robert pointed out. If I accidentally do it twice, the result of the second application is implementation dependent. This is what I did not know. Regards, Hayashi 2012/12/13 Robert Klemme > On Wed, Dec 12, 2012 at 7:11 PM, Bartosz Dziewo=C5=84ski > wrote: > > Jan, Robert, yes, but that's not the point. > > > > The same happens with a StringIO: > > > > irb(main):010:0> require 'stringio' > > =3D> true > > irb(main):014:0> io =3D StringIO.new "a\nb\nc\nd\ne" > > =3D> # > > irb(main):015:0> [1].zip(io.each){|a,b| p a,b } > > 1 > > "a\n" > > =3D> nil > > irb(main):016:0> io.read > > =3D> "c\nd\ne" > > > > I suggest you report a bug on http://bugs.ruby-lang.org/, as this > > doesn't look like the correct behavior. > > I won't do that because first it's an abuse of #zip and second I am > not convinced yet that the behavior is caused by the way streams work. > > Kind regards > > robert > > -- > remember.guy do |as, often| as.you_can - without end > http://blog.rubybestpractices.com/ > > --047d7bf0d490cf076a04d0bdd9e8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thanks all,

I have tried the same script with= JRuby 1.7.0 also, and I got:

1: 111
2:<= /div>

Not only the second line but also the third line d= isappears.
Replacing arrays with ranges did not change the output.
I ch= ecked StringIO also and got the same.

So, my concl= usion is that Enumerable#zip can be applied to IO
Enumerable=C2= =A0object only once, as Robert pointed out. If I accidentally
do it twice,=C2=A0the result of the second application is implementati= on dependent.
This is what I did not know.

Regards,
Hayashi



2012/12/13 Robert Klemme &= lt;shortcut= ter@googlemail.com>
On Wed, Dec 12, 2012 at 7:11 PM, Ba= rtosz Dziewo=C5=84ski <matma.rex@= gmail.com> wrote:
> Jan, Robert, yes, but that's not the point.
>
> The same happens with a StringIO:
>
> irb(main):010:0> require 'stringio'
> =3D> true
> irb(main):014:0> io =3D StringIO.new "a\nb\nc\nd\ne"
> =3D> #<StringIO:0x10aee00>
> irb(main):015:0> [1].zip(io.each){|a,b| p a,b }
> 1
> "a\n"
> =3D> nil
> irb(main):016:0> io.read
> =3D> "c\nd\ne"
>
> I suggest you report a bug on http://bugs.ruby-lang.org/, as this
> doesn't look like the correct behavior.

I won't do that because first it's an abuse of #zip and= second I am
not convinced yet that the behavior is caused by the way streams work.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blo= g.rubybestpractices.com/


--047d7bf0d490cf076a04d0bdd9e8--