On 9/17/06, Yukihiro Matsumoto <matz / ruby-lang.org> wrote:
> Hi,
>
> In message "Re: Splat, #to_ary and #to_a"
>     on Mon, 18 Sep 2006 11:12:43 +0900, Eero Saynatkari <eero.saynatkari / kolumbus.fi> writes:
>
> |I suppose this just qualifies as unexpected (by me) behaviour
> |but an odd thing happened when I wrote code like this:
> |
> | [*"foo\nbar"]   # => ["foo\n", "bar"]
>
> It's fixed in 1.9.  1.8 will remain as it is now for the sake of
> compatibility.

Hmmmm,

Just what is the fix in 1.9.

Are you saying that
[*"foo\nbar"] #=> ["foo\nbar"]
in 1.9?

How about:
[*(1..4)]
which in 1.8.x produces [1, 2, 3, 4]

and which of these will change in 1.9?

def a(*arg)
     p arg
end

a("foo\nbar")
which in 1.8.4 prints ["foo\nbar"]

a((1..3))
 prints [1, 2, 3, 4]
a(1..3)
 prints [1..3]


a(1..3, "foo\nbar")
prints [1..3, "foo\nbar"]

a(*"foo\nbar")
prints ["foo\n", "bar"]

a(*(1..4))
prints [1, 2, 3, 4]


  *a = "foo\nbar"
  a gets  ["foo\nbar"]
  *a = (1..4)
  a gets  [1..4]
  *a = "foo\nbar", (1..3)
  a gets ["foo\nbar", 1..3]

I'm not sure that I see a consistent pattern here.  But I have to say
that I think that the 1.8.x interpretations of

a(*"foo\nbar")
and
a(*(1..4))

both make sense since the caller is ASKING for the splat, and that
these two seem very similar to the
[*"foo\nbar"]
case which started this.


I've also always been surprised that String#to_a didn't produce an
array of single character strings, instead of splitting the string
into lines, but that's probably just a personal surprise, and I
wouldn't expect that to change.


-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/