Skip to content

Instantly share code, notes, and snippets.

@nicksieger
Forked from wycats/wtf.rb
Created March 28, 2010 19:53
Show Gist options
  • Save nicksieger/346984 to your computer and use it in GitHub Desktop.
Save nicksieger/346984 to your computer and use it in GitHub Desktop.
class Foo < String
attr_reader :omg
def initialize(str, omg)
super str
@omg = omg
end
def hash
[@omg, to_str].hash
end
def eql?(other)
[@omg, to_str] == [other.omg, other.to_str]
end
def inspect
"#<Foo:#{object_id} @omg: #{@omg} #{self.to_str}>"
end
end
foo = Foo.new("holla", 1)
bar = Foo.new("holla", 2)
p foo, bar
x = {}
x[foo] = 1
x[bar] = 2
p x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment