Files
wren/doc/site/classes.markdown
T
Bob Nystrom f4982f7b21 docs: add classes documentation content, usage page stub, and fix page title in template
Add full introductory content to the classes documentation page covering class definition, inheritance, and the Object superclass. Create a new usage documentation page with a TODO placeholder. Update the HTML page title format from "wren {title}" to "Wren - {title}" and add a navigation link to the new usage page.
2013-11-23 22:52:50 +00:00

949 B

^title Classes

Every value in Wren is an object, and every object is an instance of a class. Even true and false are full-featured objects, instances of the Bool class.

Defining a class

Classes are created using the class keyword, unsurprisingly:

:::wren
class Unicorn {}

This creates a class named Unicorn with no methods or fields.

TODO: methods

Inheritance

A class can inherit from a "parent" or superclass. When you invoke a method on an object of some class, if it can't be found, it walks up the chain of superclasses looking for it there.

By default, any new class inherits from Object, which is the superclass from which all other classes ultimately descend. You can specify a different parent class using is when you declare the class:

:::class
class Pegasus is Unicorn {}

This declares a new class Pegasus that inherits from Unicorn.

TODO metaclasses, supercalls, fields, etc.