Is it bug? for

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

Hi,

In message “Re: is it bug? for”
on Sat, 30 Jun 2007 21:57:03 +0900, Chung C. [email protected]
writes:

|[[email protected] ~]# ruby -v
|ruby 1.9.0 (2007-06-30 patchlevel 0) [i686-linux]
|[[email protected] ~]# irb
|irb(main):001:0> “hello”.to_a
|NoMethodError: undefined method to_a' for "hello":String | from (irb):1:inmethod_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.

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

[[email protected] ~]# ruby -v
ruby 1.9.0 (2007-06-30 patchlevel 0) [i686-linux]
[[email protected] ~]# irb
irb(main):001:0> “hello”.to_a
NoMethodError: undefined method to_a' for "hello":String from (irb):1:inmethod_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…

Dear Chung C.,

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

Hi,

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

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

On 6/30/07, Bertram S. [email protected] wrote:

Rubbish. It’s

def to_a
   split $/
end

or maybe even:

alias_method :to_a, :lines

On 6/30/07, Axel E. [email protected] wrote:

You can change that by writing it:
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”]

-------- Original-Nachricht --------
Datum: Sat, 30 Jun 2007 22:54:34 +0900
Von: Bertram S. [email protected]
An: [email protected]
Betreff: Re: is it bug? for

Rubbish. It’s

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

Best regards

Axel

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

On 6/30/07, Axel E. [email protected] 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”]

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

On 6/30/07, Axel E. [email protected] wrote:

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

On 6/30/07, Axel E. [email protected] 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 …

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

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

On 6/30/07, Axel E. [email protected] wrote:

So the confusion is about etiquette rather than content.

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs