Ruby code
Ruby runs as CRuby compiled to WebAssembly. No Ruby is required on your machine.
The API
Section titled “The API”| Symbol | Role |
|---|---|
$input | The value received on the input port, already decoded from JSON |
$vars | The run variables |
puts | Writes to the execution log |
| The last expression | Its value leaves on the result port, JSON-encoded |
Note the global variables ($input, $vars): that is the Ruby convention for
whatever comes from outside the script.
Example
Section titled “Example”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 }Standard library
Section titled “Standard library”Ruby’s standard library is available: json, digest, base64, time, uri,
set…
require "digest"
{ "empreinte" => Digest::SHA256.hexdigest($input["corps"]) }External packages
Section titled “External packages”The packages field accepts pure-Ruby gems. A gem containing a native
extension is refused and execution leaves via the error port.