Skip to main content

Ruby

Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.

LiveCodes runs Ruby in the browser using Opal.

Opal is a Ruby to JavaScript source-to-source compiler. It comes packed with the Ruby corelib you know and love. It is both fast as a runtime and small in its footprint.

opalrb.com

Note

LiveCodes also supports running Ruby using ruby.wasm which is a collection of WebAssembly ports of the official CRuby. Read documentation here

Usage​

LiveCodes runs Ruby in the browser, including corelib and the supported stdlib.

JavaScript interoperability and DOM access is achieved using "Native" module. See the starter template for an example.

Language Info​

Name​

ruby

Extension​

.rb

Editor​

script

Compiler​

Opal

Version​

Opal v1.8.2

Code Formatting​

Not supported for Ruby.

Example Usage​

show code
import { createPlayground } from 'livecodes';

const options = {
"params": {
"ruby": "class User\n attr_accessor :name\n\n def initialize(name)\n @name = name\n end\n\n def admin?\n @name == 'Admin'\n end\nend\n\nuser = User.new('Bob')\n\n# the output will go to the console\nputs user\nputs user.admin?\n",
"console": "full"
}
};
createPlayground('#container', options);

This example demonstrates stdlib usage, JavaScript interoperability and DOM access:

show code
import { createPlayground } from 'livecodes';

const options = {
"template": "ruby"
};
createPlayground('#container', options);

Starter Template​

https://livecodes.io/?template=ruby