Add subtype test
This commit is contained in:
parent
c6417fb0d3
commit
989058e4d7
1 changed files with 16 additions and 0 deletions
|
|
@ -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
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue