Project

General

Profile

Actions

Bug #4914

closed

Array#index fails when used in if statement assignment

Added by bterkuile (Benjamin ter Kuile) over 13 years ago. Updated over 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
Backport:
[ruby-core:37268]

Description

cat /etc/issue: Ubuntu 11.04
rvm -v: rvm 1.6.2
rvm 1.9.2, ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
Also tested with: rvm 1.9.2-head, ruby -v: ruby 1.9.2p274 (2011-06-06 revision 31932) [x86_64-linux]

Test code:

a = [:a, :b, :c]
for k in 'a'..'c'
if i = a.index(k.to_sym) && k.to_s =~ /b/
puts i
end
end
for k in 'a'..'c'
i = a.index(k.to_sym)
if i && k.to_s =~ /b/
puts i
end
end

output:
0
1

expected output:
1
1

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0