Ruby-Code
Ruby läuft als zu WebAssembly kompiliertes CRuby. Auf Ihrem Rechner ist kein Ruby erforderlich.
Die API
Section titled “Die API”| Symbol | Rolle |
|---|---|
$input | Der auf dem Eingangsport empfangene Wert, bereits aus JSON dekodiert |
$vars | Die Run-Variablen |
puts | Schreibt in das Ausführungslog |
| Der letzte Ausdruck | Sein Wert geht an den Port result, kodiert in JSON |
Beachten Sie die globalen Variablen ($input, $vars): Das ist die
Ruby-Konvention für alles, was von außerhalb des Skripts kommt.
Beispiel
Section titled “Beispiel”commandes = $input["commandes"]
payees = commandes.select { |c| c["statut"] == "payee" }total = payees.sum { |c| c["montant"] }
puts "#{payees.size} commandes payées, total #{total} €"
{ "nombre" => payees.size, "total" => total }Standardbibliothek
Section titled “Standardbibliothek”Die Standardbibliothek von Ruby steht zur Verfügung: json, digest,
base64, time, uri, set …
require "digest"
{ "empreinte" => Digest::SHA256.hexdigest($input["corps"]) }Externe Pakete
Section titled “Externe Pakete”Das Feld packages akzeptiert reine Ruby-Gems. Ein Gem mit einer
nativen Erweiterung wird abgelehnt, und die Ausführung geht an den Port
error.