Project

General

Profile

Bug #9381

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

=begin 
 Ruby 2.1.0 won't fetch objects when the lookup key overrides `#hash` (({#hash})) and `#eql?`. (({#eql?})). 
 This is a regression as it works as expected in ruby 1.8, 1.9 and 2.0. 

 ```ruby 
 

  class Wrapper 
   
    def initialize(obj) 
     
      @obj = obj 
   
    end 

   

    def method_missing(symbol, *args, &block) 
     
      @obj.__send__(symbol, *args, &block) 
   
    end 

   

    def hash 
     
      @obj.hash 
   
    end 

   

    def eql?(other) 
     
      @obj.eql?(other) 
   
    end 
 
  end 

 

  hash = { 5 => "LOOKUP SUCCEEDED" } 

 

  # Prints "LOOKUP SUCCEEDED" on RUBY < 2.1.0. Fails on RUBY 2.1.0. 
 
  p hash[Wrapper.new(5)] 
 ``` =end 

Back