Run Ruby code in Google Sheets using mruby/edge
sheetruby embeds the mruby/edge VM into Google Apps Script, allowing you to execute Ruby code directly in your spreadsheets. It compiles to WebAssembly and runs entirely within Google Sheets' Apps Script environment.
- Open your Google Spreadsheet
- Go to Extensions → Apps Script
- Copy the contents of
combined.jsand paste it into the script editor - Save the script
- Return to your spreadsheet - the
EVAL_RUBY_SCRIPT()function is now available!
EVAL_RUBY_SCRIPT(ruby_code, [arg1], [arg2], [arg3])- First argument (required): Ruby script code
- Can be a string literal or reference to a cell
- Arguments 2-4 (optional): Data to pass to the Ruby script
- Can reference cells or ranges
- Accessible in Ruby as global variables
$arg1,$arg2,$arg3 - Currently supports up to 3 arguments
- Single cell: Type is automatically inferred (number, string, boolean)
- Multiple cells: Passed as a 2D array (Array of Arrays)
- Return value: Type is automatically inferred from Ruby result via JSON serialization
Basic calculation:
=EVAL_RUBY_SCRIPT("1 + 2")
# => 3Using cell references:
=EVAL_RUBY_SCRIPT("$arg1 * 2", A1)
# If A1 = 21, returns 42Array processing:
=EVAL_RUBY_SCRIPT("$arg1.map { |x| x * $arg2 }", A1:A3, B1)
# If A1:A3 = [[1], [2], [3]] and B1 = 10
# Returns [10, 20, 30]Multiple arguments:
=EVAL_RUBY_SCRIPT("$arg1 + $arg2 + $arg3", A1, B1, C1)
# Sum of three cellsString manipulation:
=EVAL_RUBY_SCRIPT("$arg1.upcase", A1)
# If A1 = "hello", returns "HELLO"Math functions (with mrubyedge-math):
=EVAL_RUBY_SCRIPT("Math.sqrt($arg1)", 16)
# => 4.0-
Install Emscripten SDK
git clone https://github.com/emscripten-core/emsdk.git cd emsdk ./emsdk install latest ./emsdk activate latest source ./emsdk_env.sh
-
Install Rust with the
wasm32-unknown-emscriptentarget:rustup target add wasm32-unknown-emscripten
-
Set the
BINDGEN_EXTRA_CLANG_ARGSenvironment variable:export BINDGEN_EXTRA_CLANG_ARGS="--sysroot=$EMSDK/upstream/emscripten/cache/sysroot"
make buildThis will generate combined.js in the project root.
Bug reports and contributions are welcome! Please feel free to:
- Report issues on GitHub Issues
- Submit pull requests
- Share your use cases and feedback
See LICENSE file for details.