From 989058e4d7866ee5fb29c1297aac950c864fc182 Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Tue, 26 May 2015 16:00:15 -0400 Subject: [PATCH] Add subtype test --- content/oop.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/content/oop.md b/content/oop.md index 2e3870c..9edbdd7 100644 --- a/content/oop.md +++ b/content/oop.md @@ -38,3 +38,19 @@ woof meow 10 ``` + +## Testing subtypes + +It is also possible to check if an object is of a given subtype with the `of` keyword. For example, + +``` nimrod +echo(animals[0] of Dog) +echo(animals[0] of Cat) +echo(animals[0] of Animal) +``` +``` console +$ nim c -r of_op.nim +true +false +true +```