Ruby in the Browser

Opal compiles ruby ahead of time into javascript to run on the client. Opal supports blocks, procs, classes, modules and more!

method_missing

Opal fully supports `method_missing` on all objects and classes to allow full metaprogramming on the client.

Native class

`Native` is a class provided to wrap native objects so that their properties and methods can be called directly from ruby code.

Inline Javascript

X-Strings in opal are used to write javascript within ruby code, making it easier to call and wrap javascript code within your code.

opal-parser

`opal-parser.js` allows you to compile and run ruby code directly from script tags or strings for runtime `eval()` support.

Easy Debugging

Opal compiles into clean, readable code to help with debugging. Variables, ivars and method names are preserved in the output.

Getting Started

Overview

[1, 2, 3, 4].each do |a|
  puts a
end

class Foo
  attr_accessor :name

  def method_missing(sym, *args, &block)
    puts "You tried to call: #{sym}"
  end
end

adam = Foo.new
adam.name = 'Adam Beynon'
puts adam.name
adam.do_task

  # Output (in your browser console):
  #
  #   1
  #   2
  #   3
  #   4
  #   Adam Beynon
  #   You tried to call: do_task

Try this code in your browser!

Installation

Install Opal from RubyGems:

$ gem install opal

Or include it in your Gemfile for Bundler:

gem 'opal'