Is it bug? for

[root@home1 ~]# ruby -v
ruby 1.9.0 (2007-06-30 patchlevel 0) [i686-linux]
[root@home1 ~]# irb
irb(main):001:0> "hello".to_a
NoMethodError: undefined method `to_a' for "hello":String
        from (irb):1:in `method_missing'
        from (irb):1
        from
/root/Desktop/ruby-trunk/trunk/build/lib/ruby/1.9/irb.rb:150:in `bl

···

--
Posted via http://www.ruby-forum.com/.

Hi,

···

In message "Re: is it bug? for" on Sat, 30 Jun 2007 21:57:03 +0900, Chung Chung <bkeh12@gmail.com> writes:

[root@home1 ~]# ruby -v
ruby 1.9.0 (2007-06-30 patchlevel 0) [i686-linux]
[root@home1 ~]# irb
irb(main):001:0> "hello".to_a
NoMethodError: undefined method `to_a' for "hello":String
       from (irb):1:in `method_missing'
       from (irb):1
       from
/root/Desktop/ruby-trunk/trunk/build/lib/ruby/1.9/irb.rb:150:in `bl

No, it's not a bug. In 1.9, Strings are no longer Enumerable based on
lines. Instead, use "lines" explicitly.

              matz.

Implict to_a in Object is removed in 1.9 !?

In 1.8.6 there was an deprecation warning...

···

On Saturday 30 June 2007 14:57:03 Chung Chung wrote:

[root@home1 ~]# ruby -v
ruby 1.9.0 (2007-06-30 patchlevel 0) [i686-linux]
[root@home1 ~]# irb
irb(main):001:0> "hello".to_a
NoMethodError: undefined method `to_a' for "hello":String
        from (irb):1:in `method_missing'
        from (irb):1
        from
/root/Desktop/ruby-trunk/trunk/build/lib/ruby/1.9/irb.rb:150:in `bl

Dear Chung Chung,

no it's not a bug. The error message you get means that
there is no method "to_s" defined that will turn a String
into an Array.
You can change that by writing it:

class String
   def to_a
       return [self]
   end
end

a="a string"
p a.to_a =>["a string"]

or simply by putting brackets around whatever
String you have.

Best regards,

Axel

···

--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

Hi,

···

Am Samstag, 30. Jun 2007, 22:17:24 +0900 schrieb Axel Etzold:

You can change that by writing it:

class String
   def to_a
       return [self]
   end
end

Rubbish. It's

    def to_a
       split $/
    end

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

-------- Original-Nachricht --------

···

Datum: Sat, 30 Jun 2007 22:54:34 +0900
Von: Bertram Scharpf <lists@bertram-scharpf.de>
An: ruby-talk@ruby-lang.org
Betreff: Re: is it bug? for

Hi,

Am Samstag, 30. Jun 2007, 22:17:24 +0900 schrieb Axel Etzold:
> You can change that by writing it:
>
> class String
> def to_a
> return [self]
> end
> end

Rubbish. It's

So what's the difference between your output and mine,
except for the degree of etiquette ?

Best regards

Axel

--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: GMX E-Mail ✉ sichere & kostenlose E-Mail-Adresse ✉

or maybe even:

alias_method :to_a, :lines

···

On 6/30/07, Bertram Scharpf <lists@bertram-scharpf.de> wrote:

Rubbish. It's

    def to_a
       split $/
    end

-------- Original-Nachricht --------
Datum: Sat, 30 Jun 2007 22:54:34 +0900
Von: Bertram Scharpf <lists@bertram-scharpf.de>
An: ruby-talk@ruby-lang.org
Betreff: Re: is it bug? for

> Hi,
>
> > You can change that by writing it:
> >
> > class String
> > def to_a
> > return [self]
> > end
> > end
>
> Rubbish. It's

So what's the difference between your output and mine,
except for the degree of etiquette ?

Well, yours isn't correct. On 1.8:

"a\nb\nc\n".to_a

=> ["a\n", "b\n", "c\n"]

The code you mentioned is just:

["a\nb\nc\n"]

···

On 6/30/07, Axel Etzold <AEtzold@gmx.de> wrote:

> Am Samstag, 30. Jun 2007, 22:17:24 +0900 schrieb Axel Etzold:

Well, yours isn't correct. On 1.8:

>> "a\nb\nc\n".to_a
=> ["a\n", "b\n", "c\n"]

The code you mentioned is just:

["a\nb\nc\n"]

Ok, but do you know that that's what the OP wanted ?
Best regards,

Axel

···

--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger

> Well, yours isn't correct. On 1.8:
>
> >> "a\nb\nc\n".to_a
> => ["a\n", "b\n", "c\n"]
>
> The code you mentioned is just:
>
> ["a\nb\nc\n"]
Ok, but do you know that that's what the OP wanted ?
Best regards,

I can only assume so seeing as this is the behaviour of String#to_a in
1.8 and it does not exist in 1.9

But no, he'd need to answer that. Typically if you want to do that
kind of manipulation, Array() is better, anyhow.

Array([1,2,3])

=> [1, 2, 3]

Array("foo")

=> ["foo"]

···

On 6/30/07, Axel Etzold <AEtzold@gmx.de> wrote:

Dear Gregory,

I can only assume so seeing as this is the behaviour of String#to_a in
1.8 and it does not exist in 1.9

But no, he'd need to answer that. Typically if you want to do that
kind of manipulation, Array() is better, anyhow.

>> Array([1,2,3])
=> [1, 2, 3]
>> Array("foo")
=> ["foo"]

Well thank you. I was just writing because I feel you should be
careful before you start hurling "rubbish" at other people - maybe
in the context they wanted, something else might be more appropriate ...
e.g., if you create word lists from texts, as I had to lately quite
a lot.
I wouldn't have answered anyway had I seen Matz's response (just a minute earlier than mine.)

Best regards,

Axel

···

--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger

I wasn't the one who said Rubbish, actually. That was Bertram.
(Which I thought was rude, too)

···

On 6/30/07, Axel Etzold <AEtzold@gmx.de> wrote:

Dear Gregory,

> I can only assume so seeing as this is the behaviour of String#to_a in
> 1.8 and it does not exist in 1.9
>
> But no, he'd need to answer that. Typically if you want to do that
> kind of manipulation, Array() is better, anyhow.
>
> >> Array([1,2,3])
> => [1, 2, 3]
> >> Array("foo")
> => ["foo"]

Well thank you. I was just writing because I feel you should be
careful before you start hurling "rubbish" at other people - maybe
in the context they wanted, something else might be more appropriate ...
e.g., if you create word lists from texts, as I had to lately quite
a lot.

I wasn't the one who said Rubbish, actually. That was Bertram.
(Which I thought was rude, too)

I know and I'm not blaming you, of course ...

Best regards,

Axel

···

--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger

I don't really understand what you're upset about then. You asked if
there was a difference between what Bertram wrote and what you did,
and there absolutely is. His splits by line, mirroring the behaviour
of 1.8

But I suggested perhaps aliasing to String#lines, since it is the more
powerful replacement for String#to_a

Though your suggestion might be useful for something, when you want to
do array coercion, Array() is what should be used. The behaviour you
suggested, just wrapping in brackets, is what Object#to_a does and
it's IMO a good thing that this is removed in 1.9

···

On 6/30/07, Axel Etzold <AEtzold@gmx.de> wrote:

> I wasn't the one who said Rubbish, actually. That was Bertram.
> (Which I thought was rude, too)
I know and I'm not blaming you, of course ...

Dear Gregory,

I was just trying to say that one shouldn't say "rubbish" to something you don't know in what relation it was. We two have agreed on that
earlier, so I was trying to say thank you to you about that in
my last email and stop it there ... nothing more.
So the confusion is about etiquette rather than content.
Let's just stop it here and try to solve more complex
problems, mine for instance.

Best regards,

Axel

···

--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail

It's also about content. Introducing new behaviour for a removed
method that doesn't reflect its history is confusing. It means that
code which used String#to_a on Ruby 1.8 would not immediately throw an
error on 1.9 with your change, but rather would just behave
incorrectly.

I would much rather see a compatible monkeypatch, if it is needed at
all. So really, what you suggested is a bad idea. That's what I was
trying to say. If the OP wanted that kind of behaviour, it shouldn't
be called to_a.

···

On 6/30/07, Axel Etzold <AEtzold@gmx.de> wrote:

So the confusion is about etiquette rather than content.