On Sat, Feb 23, 2013 at 2:00 PM, Bartosz DziewoƄski <[email protected]> wrote:
> On Sat, 23 Feb 2013 13:44:25 +0100, Matthew Kerwin <[email protected]>
> wrote:
>
>> I know, I know. I wasn't paying attention while typing and didn't realise
>> how bad it was. I edited the post immediately on the forum interface, but
>> apparently the mailing list version got sent first.
>>
>> I think it now says something like "Splat is an array operation, Range is
>> not an array."
>
>
> But you can splat a range?
>
> irb(main):004:0> a, b, c = *0..2
> => [0, 1, 2]
> irb(main):005:0> a
> => 0
> irb(main):006:0> b
> => 1
> irb(main):007:0> c
> => 2
>
> Are we misunderstanding each other?

You created an explicit implicit Array conversion by using "*" on the
right side.  The point Matthew and I were trying to make is that you
cannot do the same with a range without the splat operator on the
right side:

irb(main):004:0> a, b, c = 0..2
=> 0..2
irb(main):005:0> a
=> 0..2
irb(main):006:0> b
=> nil
irb(main):007:0> c
=> nil

Whereas with an Array you can:

irb(main):012:0> a, b, c = [0, 1, 2]
=> [0, 1, 2]
irb(main):013:0> a
=> 0
irb(main):014:0> b
=> 1
irb(main):015:0> c
=> 2

Cheers

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- 
[email protected] | 
https://groups.google.com/d/forum/ruby-talk-google?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"ruby-talk-google" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to