Ruby
The Ruby Action allows you to execute Ruby code directly inside your workflow.
Ruby Action
(Screenshot unavailable — image was removed from the original source.)
The Ruby Action allows you to execute Ruby code directly inside your workflow.
The code you write is executed as the body of a function, meaning:
- You can use
putsto print to standard output logs. - You can return simple values, arrays, objects, or complex structures.
Ruby Actions are ideal for data manipulation, HTTP calls, JSON/XML parsing, statistics, templating, and custom business logic.
Available Gems
The following gems are preinstalled and available:
Data manipulation
jmespathjsonpathnokogiri
HTTP client
httpx
Auth / tokens
jwt
Utilities
liquidreverse_markdownfaker
Statistics
descriptive_statistics
You can freely require any of these gems inside the Ruby Action.
Usage Examples
Return a simple value
return "Hello from Ruby!"Return a list
return [1, 2, 3, "abc"]Return an object
return { success: true, message: "Done" }Use standard output
puts "Debug message"
return "OK"Raise error
raise "Something went wrong!"HTTP Requests (HTTPX)
require "httpx"
require "json"
resp = HTTPX.get("https://httpbin.org/json")
raise "bad response" unless resp.status == 200
doc = JSON.parse(resp.to_s, symbolize_names: true)
return {
ok: true,
title: doc.dig(:slideshow, :title)
}XML Parsing (Nokogiri)
require "nokogiri"
xml = "<root><x>1</x><x>2</x></root>"
doc = Nokogiri::XML(xml)
return doc.xpath("//x").map(&:text)Extract values (JSONPath)
require "jsonpath"
doc = { "store" => { "book" => [ { "price" => 8.95 }, { "price" => 12.99 } ] } }
prices = JsonPath.new("$.store.book[*].price").on(doc)
return prices.maxAggregate values (JSONPath)
require "json"
require "jsonpath"
doc = JSON.parse('{"store":{"book":[{"price":8.95},{"price":12.99},{"price":5.50}]}}')
prices = JsonPath.new("$..book[*].price").on(doc)
return {
count: prices.size,
min: prices.min,
max: prices.max,
sum: prices.sum
}String Templates (Liquid)
require "liquid"
tpl = Liquid::Template.parse("Hello, {{ user }}! You have {{ count }} new messages.")
output = tpl.render("user" => "Razvan", "count" => 3)
return outputHTML → Markdown (ReverseMarkdown)
require "reverse_markdown"
html = "<h1>Title</h1><p>Hello <strong>world</strong> & <em>friends</em>.</p>"
md = ReverseMarkdown.convert(html)
return mdStatistics
require "descriptive_statistics"
arr = [1,2,2,3,5,8,13,21]
return({
mean: arr.mean,
median: arr.median,
variance: arr.variance,
stdev: arr.standard_deviation
})JWT Tokens
require "jwt"
payload = { user: "razvan", exp: Time.now.to_i + 3600 }
secret = "my-secret"
token = JWT.encode(payload, secret, "HS256")
decoded = JWT.decode(token, secret, true, { algorithm: "HS256" })
return {
token: token,
decoded: decoded
}Faker – Random Test Data
require "faker"
return {
name: Faker::Name.name,
email: Faker::Internet.email,
city: Faker::Address.city
}JMESPath Example
require "jmespath"
data = {
users: [
{ name: "John", age: 30 },
{ name: "Mike", age: 25 }
]
}
return JMESPath.search("users[?age > `26`].name", data)Trim, normalize, and sanitize strings
text = " Hello World "
clean = text.strip.gsub(/\s+/, " ")
return cleanRemove nils and empty strings from arrays
arr = ["a", nil, "", "b", " ", "c"]
clean = arr.map { |x| x.to_s.strip }.reject(&:empty?)
return cleanDeep-clean a hash
def deep_clean(value)
case value
when Hash
value
.map { |k, v| [k, deep_clean(v)] }
.to_h
.reject { |_k, v| v.nil? || v == "" }
when Array
value.map { |v| deep_clean(v) }.reject { |v| v.nil? || v == "" }
else
value.is_a?(String) ? value.strip : value
end
end
input = {
name: " Razvan ",
email: "",
tags: [" ruby ", nil, " ", "ai"],
details: { city: " Bucharest ", postcode: nil }
}
return deep_clean(input)Convert keys of a hash to snake_case
def snake_keys(obj)
case obj
when Hash
obj.map do |k, v|
new_key = k.to_s.gsub(/([A-Z])/, '_\1').downcase.sub(/^_/, '')
[new_key, snake_keys(v)]
end.to_h
when Array
obj.map { |v| snake_keys(v) }
else
obj
end
end
input = {
"FullName" => "Razvan",
"UserID" => 123,
"Address" => { "PostalCode" => "050000" }
}
return snake_keys(input)Normalize numeric input
values = ["10", " 20.5 ", nil, "abc", 7]
clean = values.map do |v|
Float(v) rescue nil
end.compact
return cleanDetect duplicates & uniques
arr = ["a", "b", "a", "c", "b"]
return {
unique: arr.uniq,
duplicates: arr.tally.select { |k,v| v > 1 }.keys
}Best Practices
- Always return the final output.
- Prefer structured arrays and hashes.
- Use
putsfor logging debug information. - Use the whitelisted gems listed above.
Available Ruby Gems - list
The following gems are preinstalled and can be used inside the Ruby Action.
Data Manipulation
| Gem | Version |
|---|---|
| jmespath | 1.6.2 |
| jsonpath | 1.1.5 |
| nokogiri | 1.18.9 |
HTTP Client
| Gem | Version |
|---|---|
| httpx | 1.3.1 |
Authentication / Tokens
| Gem | Version |
|---|---|
| jwt | 2.9.3 |
Utilities
| Gem | Version |
|---|---|
| hashdiff | 1.0.1 |
| liquid | 5.5.1 |
| reverse_markdown | 3.0.0 |
| faker | 3.2.2 |

