Tutorial
Browser runtime: loading…
Start with the core syntax: print output, define methods, instantiate a class, and assign values. Each runnable snippet uses the same WASM engine as the playground.
Hello, Sapphire
print writes a line. Double-quoted strings can interpolate with #{} — same idea as Ruby.
hello.spr
Press Run to execute this snippet. ⌘↵ runs from the editor.
A greet method
Next, wrap the greeting in a def. The last expression in the body is the return value.
greet.spr
Press Run to execute this snippet. ⌘↵ runs from the editor.
A Greeter class
class introduces a type. attr holds state; .new builds an instance, and self is the receiver inside methods.
greeter.spr
Press Run to execute this snippet. ⌘↵ runs from the editor.
Values and variables
Assign with =. Types are often inferred; values are objects, so numbers, strings, booleans, lists, and maps all have methods.
values.spr
Press Run to execute this snippet. ⌘↵ runs from the editor.