Repository navigation
Classes and Inheritance
Frank edited this page Jan 27, 2026
·
3 revisions
CupidScript supports classes with constructors, methods, and single inheritance.
class File {
fn new(path) {
self.path = path;
}
fn is_hidden() {
return starts_with(self.path, ".");
}
}-
fn new(...)is the constructor. - Methods are declared with
fninside the class body. -
selfrefers to the instance inside methods.
Classes are callable. Calling a class creates an instance and runs new if present:
let f = File(".secret");
print(f.is_hidden());Instance fields are dynamic and can be assigned at runtime:
f.owner = "frank";
print(f.owner);Use : Parent to inherit methods and reuse constructors:
class ImageFile : File {
fn new(path) {
super.new(path);
self.is_img = ends_with(path, ".png");
}
fn is_image() {
return self.is_img;
}
}-
superrefers to the parent class inside methods. -
super.new(...)is typically used in child constructors.
let img = ImageFile("cat.png");
print(img.is_image());
print(img.is_hidden()); // inherited