Rugo structs provide lightweight object-oriented programming using hashes with dot access. They work naturally with the require namespace system — a struct file acts as a "class."
struct Dog
name
breed
endThis creates a constructor function Dog(name, breed) that returns a hash with those fields, plus a new() alias for use with namespaces.
Any hash supports dot notation for field access:
person = {"name" => "Alice", "age" => 30}
puts person.name # Alice
person.name = "Bob" # write access
puts person.name # BobNested dot access works too:
data = {"user" => {"name" => "Alice"}}
puts data.user.name # AliceDefine methods on a struct type with def Type.method(). The first parameter self is added automatically:
# dog.rugo
struct Dog
name
breed
end
def Dog.bark()
return self.name + " says woof!"
end
def Dog.rename(new_name)
self.name = new_name
endMethods are called through the namespace after requiring the struct file:
require "dog"
rex = dog.new("Rex", "Labrador")
puts dog.bark(rex) # Rex says woof!
dog.rename(rex, "Rexy")
puts dog.bark(rex) # Rexy says woof!The namespace acts as the "class" — dog.new() creates instances, dog.bark(rex) calls methods.
Use type_of() to get the type name of any value. For structs, it returns the struct name:
rex = Dog("Rex", "Lab")
puts type_of(rex) # Dog
puts type_of("hello") # String
puts type_of(42) # Integerexamples/structs/for a full working exampledocs/modules.mdfor the require/namespace system