Skip to content

Instantly share code, notes, and snippets.

@zdavatz
Created March 16, 2011 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdavatz/872811 to your computer and use it in GitHub Desktop.
Save zdavatz/872811 to your computer and use it in GitHub Desktop.
persistable.rb
def ==(other) # :nodoc:
super(other.odba_instance)
end
@zdavatz
Copy link
Author

zdavatz commented Mar 17, 2011

class Test
attr_accessor :aaa
def ==(other)
@aaa == other.aaa
end
end

test1 = Test.new
test2 = Test.new
test1.aaa = 100
test2.aaa = 200

p (test1 == test2) #=> false

test2.aaa = 100

p (test1 == test2) #=> true

@zdavatz
Copy link
Author

zdavatz commented Mar 17, 2011

This is the definition of '==' method.
Actually, it is expected to be used for the comparison of instances
if the instance 'equals' to the other.

@zdavatz
Copy link
Author

zdavatz commented Mar 17, 2011

Usually, test1 and test2 are different object, so
(test1 == test2) becomes always 'false'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment