Forum: Ruby Strange ruby-1.9.1 array substitution answer

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Da57cffaec80533bee0d0446b3ea6fcd?d=identicon&s=25 Michel Demazure (badal)
on 2009-05-28 20:06
Strange !

arr = [1,2,3,4,5]
arr[0,2] = nil
=> ruby 1.8 : arr = [3,4,5]
=> ruby 1.9 : arr = [nil, 3,4,5]

ruby -v
ruby 1.9.1 (2008-10-28 revision 19983) [i386-mswin32]
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2009-05-28 20:28
Michel Demazure wrote:
> Strange !
>
> arr = [1,2,3,4,5]
> arr[0,2] = nil
> => ruby 1.8 : arr = [3,4,5]
> => ruby 1.9 : arr = [nil, 3,4,5]

that might be a bugI'd ask the core people.
-=r
6111b4012d1401ca83fdcea6b1d71237?d=identicon&s=25 Antonio Cangiano (Guest)
on 2009-05-28 20:32
(Received via mailing list)
On Thu, May 28, 2009 at 2:06 PM, Michel Demazure
<michel@demazure.com>wrote:

> Strange !
>
> arr = [1,2,3,4,5]
> arr[0,2] = nil
> => ruby 1.8 : arr = [3,4,5]
> => ruby 1.9 : arr = [nil, 3,4,5]
>
> ruby -v
> ruby 1.9.1 (2008-10-28 revision 19983) [i386-mswin32]


It's a bug. They either fixed it in a more recent version or it's a
Windows
specific issue. On my Mac it works as expected:

$ ruby1.9 -v
ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-darwin9]

$ irb
>> arr = [1,2,3,4,5]
=> [1, 2, 3, 4, 5]
>> arr[0,2] = nil
=> nil
>> arr
=> [3, 4, 5]

Cheers,
Antonio
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2009-05-28 20:43
> It's a bug. They either fixed it in a more recent version or it's a
> Windows
> specific issue. On my Mac it works as expected:
>
> $ ruby1.9 -v
> ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-darwin9]
>
> $ irb
>>> arr = [1,2,3,4,5]
> => [1, 2, 3, 4, 5]
>>> arr[0,2] = nil
> => nil
>>> arr
> => [3, 4, 5]


Here's what I get in Linux with TRUNK.
>> RUBY_DESCRIPTION
=> "ruby 1.9.2dev (2009-05-28 trunk 23601) [i686-linux]"
>> arr = [1,2,3,4,5]
=> [1, 2, 3, 4, 5]
>> arr[0,2] = nil
=> nil
>> arr
=> [nil, 3, 4, 5]

maybe macs are special? "Guess we're not cool enough" (from commercial).
Just kidding.
Take care.
-=r
Da57cffaec80533bee0d0446b3ea6fcd?d=identicon&s=25 Michel Demazure (badal)
on 2009-05-28 21:00
Roger Pack wrote:
>
>> It's a bug. They either fixed it in a more recent version or it's a
>> Windows
>> specific issue. On my Mac it works as expected:

> Here's what I get in Linux with TRUNK.

> maybe macs are special? "Guess we're not cool enough" (from commercial).
> Just kidding.
> Take care.
> -=r

Open source ... and many open ends
M.
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2009-05-29 00:22
(Received via mailing list)
Hi,

In message "Re: Strange ruby-1.9.1 array substitution answer"
    on Fri, 29 May 2009 03:06:18 +0900, Michel Demazure
<michel@demazure.com> writes:

|Strange !
|
|arr = [1,2,3,4,5]
|arr[0,2] = nil
|=> ruby 1.8 : arr = [3,4,5]
|=> ruby 1.9 : arr = [nil, 3,4,5]

It's a behavior change in 1.9, use

arr[0,2] = []

instead.

              matz.
Da57cffaec80533bee0d0446b3ea6fcd?d=identicon&s=25 Michel Demazure (badal)
on 2009-05-29 07:58
Yukihiro Matsumoto wrote:
>
> It's a behavior change in 1.9, use
>
> arr[0,2] = []
>
> instead.
>
>               matz.

Thanks, Matz.
It is exactly what I did.
I was not aware of the change ... or I forgot.

M.
This topic is locked and can not be replied to.