`type Animal = ref object name: string age: int proc speak(self: Animal, msg: 
string) = echo self.name & " says:" & msg proc setName(self: Animal, 
name:string) = self.name = name proc incAge(self: Animal) = self.age += 1 proc 
`$`(x:Animal ): string= $x.name & " is " & $x.age & " years old" var sparky = 
Animal(name: "Sparky", age: 10) sparky.speak("I am eating") echo sparky 
sparky.setName("John") sparky.incAge() echo sparky[] echo sparky `

Run

Reply via email to