From: Rick DeNatale Date: 2006-09-20T02:27:50+09:00 Subject: Re: Splat, #to_ary and #to_a On 9/18/06, Yukihiro Matsumoto wrote: === A reply to my questions === Thanks Matz! Summarizing Matz' reply to my use cases: 1.9 here means the version of 1.9 as of Matz' reply: Use case Splat formal parameter. def a(*arg) p arg end a("foo\nbar") 1.8 ["foo\nbar"] 1.9 ["foo\nbar"] a((1..3)) 1.8 [1..3] Note: I think I had a typo on this one in my original post. 1.9 [1..3] a(1..3) 1.8 [1..3] 1.9 [1..3] a(1..3, "foo\nbar") 1.8 [1..3, "foo\nbar"] 1.9 [1..3, "foo\nbar"] So here, once my typo is accounted for, there's no difference. Parallel assignment *a = "foo\nbar" 1.8 ["foo\nbar"] 1.9 ["foo\nbar"] *a = (1..4) 1.8 [1..4] 1.8 [1..4] *a = "foo\nbar", (1..3) 1.8 ["foo\nbar", 1..3] 1.9 ["foo\nbar", 1..3] Again no changes here. Splat's in array literal: [*"foo\nbar"] 1.8 ["foo\n", "bar"] 1.9 ["foo\nbar"] [*(1..4)] 1.8 [1, 2, 3, 4] 1.9 [1..4] Here the difference seems to be that in 1.8 the splat had an effect but in 1.9 it doesn't, at least for strings and ranges. Personally this seems like the wrong direction to me, but that's a gut reaction. The reason I THINK that it's wrong is that it looks like it seems to ignore the explicit request represented by the *. Now I can understand that it might be confusing in a case like this: def b(str) [*str] end b("a") #=> ["a"] b("foo\nbar") #=> ["foo\n", "bar"] But I'm not convinced that it's a net positive change. Convincable, but not convinced. method call with splat argument a(*"foo\nbar") 1.8 ["foo\n", "bar"] 1.9 ["foo\nbar"] a(*(1..4)) 1.8 [1, 2, 3, 4] 1.9 [1..4] Here again, it looks like an explicit request to splat the parameter is being ignored in 1.9. Note that this very case came up recently in a discussion of expanding an array in the arguments to Array#values_at like the method does itself for range arguments. Sorry I haven't installed 1.9 myself, so I'm wondering if something like (1..10).to_a.values_at(3..5) still works the same way as it does in 1.8 (returning [4, 5, 6]) or throws an exception saying that it can't convert a range to an integer similar to the way 1.8 does with: (1..10).to_a.values_at([3, 4, 5]) -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/