Strange ruby-1.9.1 array substitution answer

M

Michel Demazure

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

Roger Pack

Michel said:
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
 
A

Antonio Cangiano

[Note: parts of this message were removed to make it a legal post.]

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
 
R

Roger Pack

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
 
M

Michel Demazure

Yukihiro said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,478
Latest member
ReginaldVi

Latest Threads

Top