Skip to content

Ruby code

Ruby runs as CRuby compiled to WebAssembly. No Ruby is required on your machine.

SymbolRole
$inputThe value received on the input port, already decoded from JSON
$varsThe run variables
putsWrites to the execution log
The last expressionIts 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.

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 }

Ruby’s standard library is available: json, digest, base64, time, uri, set

require "digest"
{ "empreinte" => Digest::SHA256.hexdigest($input["corps"]) }

The packages field accepts pure-Ruby gems. A gem containing a native extension is refused and execution leaves via the error port.