Skip to content

Instantly share code, notes, and snippets.

@sorah
Created May 8, 2009 13:28
Show Gist options
  • Save sorah/108774 to your computer and use it in GitHub Desktop.
Save sorah/108774 to your computer and use it in GitHub Desktop.
a = Object.new
b = Object.new
c = "foo"
b.instance_eval{@foo = "bar"}
print "a = ";p a
print "b = ";p b
print "c = ";p c
puts "EQUAL1:"
print "a == a =>";p a == a
print "b == b =>";p b == b
print "c == c =>";p c == c
print 'c == "foo" =>';p c == "foo"
print "c == a =>";p c == a
print "a == b =>";p a == b
print "b == c =>";p b == c
print "a == c =>";p a == c
print "b == a =>";p b == a
print "c == b =>";p c == b
print 'c == 1 =>';p c == 1
ObjectSpace.each_object(Module) {|m|
m.module_eval{undef :equal?;undef :==} if m.method_defined?(:equal?)
m.module_eval{def equal?(o);true;end}
m.module_eval{def ==(o);true;end}
}
class Object
def equal?(other)
true
end
def ==(other)
true
end
end
puts "EQUAL2:"
print "a == a =>";p a == a
print "b == b =>";p b == b
print "c == c =>";p c == c
print 'c == "foo" =>';p c == "foo"
print "c == a =>";p c == a
print "a == b =>";p a == b
print "b == c =>";p b == c
print "a == c =>";p a == c
print "b == a =>";p b == a
print "c == b =>";p c == b
print 'c == 1 =>';p c == 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment