[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

is it bug? for

Chung Chung

6/30/2007 12:57:00 PM

[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-....

14 Answers

Markus Schirp

6/30/2007 1:17:00 PM

0

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

Implict to_a in Object is removed in 1.9 !?

In 1.8.6 there was an deprecation warning...

Axel Etzold

6/30/2007 1:17:00 PM

0

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/s...

Bertram Scharpf

6/30/2007 1:55:00 PM

0

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-...

Axel Etzold

6/30/2007 1:58:00 PM

0


-------- 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: http://www.gmx.net/de/g...

Gregory Brown

6/30/2007 2:00:00 PM

0

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

> Rubbish. It's
>
> def to_a
> split $/
> end

or maybe even:

alias_method :to_a, :lines

Gregory Brown

6/30/2007 2:02:00 PM

0

On 6/30/07, Axel Etzold <AEtzold@gmx.de> wrote:
>
> -------- 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 ?

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"]

Axel Etzold

6/30/2007 2:06:00 PM

0

> 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/mult...

Gregory Brown

6/30/2007 2:15:00 PM

0

On 6/30/07, Axel Etzold <AEtzold@gmx.de> wrote:
> > 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"]

Axel Etzold

6/30/2007 2:30:00 PM

0

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/mult...

Gregory Brown

6/30/2007 2:39:00 PM

0

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)