Standard Library
The standard library is split across focused modules. The list will grow over time.
Runtime Library (Amethyst.Runtime)
Section titled “Runtime Library (Amethyst.Runtime)”Low-level types and attributes required by the Amethyst runtime. Always linked — not user-facing in normal code.
| Type | Purpose |
|---|---|
Symbol |
Lightweight interned string identifier (:name) |
ControlFlowReturnException |
Non-local return from blocks |
ControlFlowBreakException |
Non-local break from blocks |
Compiler Attributes
Section titled “Compiler Attributes”| Attribute | Purpose |
|---|---|
@[AmethystName("...")] |
Preserves original snake_case name on compiled IL |
@[AnonymousArgumentAttribute] |
Marks a positional parameter |
@[KeywordArgumentAttribute] |
Marks a keyword parameter |
@[Property] |
Forces a method to be emitted as a .NET property |
Base Protocols and Mixins
Section titled “Base Protocols and Mixins”| Name | Kind | Purpose |
|---|---|---|
Comparable[T] |
Protocol | <=> ordering |
Hashable |
Protocol | hash() for use as hash keys |
Equatable[T] |
Protocol | == equality |
DynamicMessages |
Mixin | Opt-in arbitrary message dispatch |
Class Library (Amethyst.Core)
Section titled “Class Library (Amethyst.Core)”Extensions to the .NET class library. Included by default in all Amethyst projects.
Enumerable[T] Mixin
Section titled “Enumerable[T] Mixin”Provides collection operations to any type that implements each. Included explicitly
for Amethyst types, synthesised automatically for types implementing .NET’s
IEnumerable[T]:
# Amethyst type — explicit inclusionclass NumberList include Enumerable[Int]
def each(&block: (Int) -> Void): Void @items.each(&block) endend
# .NET type — synthesised automaticallylist = List[String].new # gets map, select, etc. via IEnumerable[T]Available methods include: map, select, reject, reduce, each_with_index,
flat_map, any?, all?, none?, count, first, last, min, max,
min_by, max_by, sort, sort_by, group_by, zip, take, drop,
each_slice, each_cons, to_array, to_hash.
Disposable
Section titled “Disposable”Disposable is Amethyst’s name for .NET’s System.IDisposable. Amethyst types adopt it
with implements Disposable and define dispose. .NET types that implement
IDisposable are already Disposable.
use passes the object to a block and calls dispose when the block finishes, however
it finishes: normally, by raising, or through a non-local return or break. It takes
the place of C#’s using statement:
StreamReader.new("data.csv").use do |reader| puts reader.read_to_endendOpen Questions [TBD]
Section titled “Open Questions [TBD]”- What
usereturns (for example, the block’s value) - Asynchronous disposal (
System.IAsyncDisposable)
String Extensions
Section titled “String Extensions”Common string utilities on top of System.String.
Kernel Methods
Section titled “Kernel Methods”Top-level methods available everywhere without imports, provided by Amethyst::Kernel
which is mixed into every object:
puts "hello" # print with newlineprint "hello" # print without newlinep value # inspect and printpp value # pretty-printrand(n) # random number 0...nsleep(seconds) # pause executionExtending the Kernel
Section titled “Extending the Kernel”Amethyst::Kernel can be extended to add globally available methods:
extension class Amethyst::Kernel def log(message: String): Void puts "[#{Time.now}] #{message}" endend
# Available everywhere:log "server started"Testing Framework (Amethyst.Test)
Section titled “Testing Framework (Amethyst.Test)”An RSpec-inspired testing framework, added as a dependency — not built into the SDK. This allows users to swap it for another framework if preferred.
am add Amethyst.TestStructure
Section titled “Structure”describe UserService do let(:service) { UserService.new }
before do # setup end
context "when user is valid" do it "saves the user" do user = User.new(name: "Alice") expect(service.save(user)).to be_truthy end end
context "when user is invalid" do it "raises an error" do expect { service.save(nil) }.to raise_error(ValidationException) end endendFeatures
Section titled “Features”describe/context— test groupingit— individual test caselet/let!— lazy and eager test valuesbefore/after— setup and teardown hooksexpect(x).to matcher— assertions- Built-in matchers:
eq,be_truthy,be_falsy,be_nil,raise_error,include,match,be_a,be_between