Learn about objects

This commit is contained in:
mollusk 2019-12-17 09:37:42 -07:00
parent e752b2ac26
commit 7abf04edd7

View File

@ -1,6 +1,6 @@
# This is just an example to get you started. A typical binary package # This is just an example to get you started. A typical binary package
# uses this file as the main entry point of the application. # uses this file as the main entry point of the application.
import system, os, random, strutils,typetraits import system, os, random, strutils, typetraits, strformat
when isMainModule: when isMainModule:
#[ #[
@ -19,7 +19,35 @@ when isMainModule:
for line in lines: for line in lines:
f.writeLine(line.toUpper) f.writeLine(line.toUpper)
]# ]#
#[
type
Person = object
name: string
age: int
cases: int
let people = [
Person(name: "Allison", age: 25, cases: 80),
Person(name: "Mike", age: 40, cases: 100)
]
for person in people:
echo(fmt"{person.name} is {person.age} years old and threw {person.cases} cases")
]#
proc testOop() =
type
Dog = object
proc bark(self: Dog) =
echo "Woof"
proc drink(self: Dog) =
echo "Gulp"
let dog = Dog()
dog.bark()
dog.drink()
proc geussNum() = proc geussNum() =
randomize() randomize()
@ -78,6 +106,8 @@ scatter [-a, -b, -k, -r]
echo "kill" echo "kill"
of "-r": of "-r":
geussNum() geussNum()
of "-t":
testOop()
of "-h", "--help": of "-h", "--help":
echo help() echo help()
else: else: