- 
      
- 
        Save toretore/9078144 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Foo | |
| attr_reader :v | |
| def initialize(v) | |
| @v = v | |
| end | |
| def hash | |
| v.hash | |
| end | |
| def eql?(o) | |
| puts "Foo#eql? called" | |
| if o.is_a?(self.class) | |
| o.v.eql?(v) | |
| else | |
| o.eql?(v) | |
| end | |
| end | |
| end | |
| h = {} | |
| f = Foo.new('hello') | |
| h[f] = 'world' | |
| h['hello'] = 'jupiter' | |
| p h[f] | |
| p h['hello'] | |
| p h | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment