But this seems to be my first ruby bug which I sumbled across while fising hash_test.rb. 1.8.7 behaves different compared to 1.9.2
testhash = {
'1' => 'a',
'2' => 'b',
'3' => 'c'
}
puts "#{testhash.index('a')}" # => 1
testhash['3'] = 'a'
puts "#{testhash.index('a')}" # => 1
testhash.delete('1')
puts "#{testhash.index('a')}" # => 3
testhash['4'] = 'a'
puts "#{testhash.index('a')}" # => 3
testhash['3'] = 'x'
puts "#{testhash.index('a')}" # => 4
testhash['3'] = 'a'
puts "#{testhash.index('a')}" # => 3
testhash['1'] = 'a'
puts "#{testhash.index('a')}" # => 3 with ruby 1.9.1p243
'1' => 'a',
'2' => 'b',
'3' => 'c'
}
puts "#{testhash.index('a')}" # => 1
testhash['3'] = 'a'
puts "#{testhash.index('a')}" # => 1
testhash.delete('1')
puts "#{testhash.index('a')}" # => 3
testhash['4'] = 'a'
puts "#{testhash.index('a')}" # => 3
testhash['3'] = 'x'
puts "#{testhash.index('a')}" # => 4
testhash['3'] = 'a'
puts "#{testhash.index('a')}" # => 3
testhash['1'] = 'a'
puts "#{testhash.index('a')}" # => 3 with ruby 1.9.1p243
# => 1 with ruby 1.8.7
I had a look into the spec http://ruby-doc.org/core/classes/Hash.html#M002855 but imho this isn't clear. I also had a look here: https://github.com/rubyspec/rubyspec/tree/master/core/hash/, to be more precise, here: https://github.com/rubyspec/rubyspec/blob/master/core/hash/shared/index.rb
it "returns the corresponding key for value" do
new_hash(2 => 'a', 1 => 'b').send(@method, 'b').should == 1
end
But shouln'd there be somthing like
new_hash(2 => 'a', 1 => 'b').send(@method, 'b').should == 1
end
But shouln'd there be somthing like
it "returns the first corresponding key for value if there is more then once occurance of value" do
new_hash(1 => 'a', 2 => 'b', 3 => 'a').send(@method, 'a').should == 1
end
new_hash(1 => 'a', 2 => 'b', 3 => 'a').send(@method, 'a').should == 1
end
As I didn't want to raise a newbe-nonsense-defect in the issue tracking system http://redmine.ruby-lang.org/ and as I didn't wan't to ask silly-newbie-questions in the mailing list http://www.ruby-lang.org/de/community/mailing-lists/#ruby-core I went for a german forum (which is directly linked from www.ruby-lang.org):
This is my first post: bug in ruby 1.8.7 in hash.index?
Keine Kommentare:
Kommentar veröffentlichen