Skip to content

Instantly share code, notes, and snippets.

@gokr
Created December 10, 2014 23:30
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 gokr/73cb41ac285611ba047a to your computer and use it in GitHub Desktop.
Save gokr/73cb41ac285611ba047a to your computer and use it in GitHub Desktop.
Inheritance of ==?
type
Vehicle* = ref object of RootRef
color*: string
type
Car* = ref object of Vehicle
make*: string
# This method ... is never called, it seems
# that system.`==` is preferred, why?
method `==`*(self, other: Vehicle): bool =
echo "why can't we get here?"
true
# If we enable this method it will be used
#method `==`*(self, other: Car): bool =
# echo "this one works"
# true
var volvo = Car(color: "blue", make: "Volvo")
var saab = Car(color: "red", make: "Saab")
echo(volvo == saab)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment