Sonntag, 21. November 2010

my first ruby bug?

as announced in my last post I fixed regexp_test.rb, hash_test.rb and open3_test.rb. If you are interested in the details have a look at github: https://github.com/SlevinMcGuigan/SMG--learn

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 with ruby 1.8.7

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

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