Skip to content
Oeiuwq Faith Blog OpenSource Porfolio

timimahoney/decaf

Ruby in the browser.

timimahoney/decaf.json
{
"createdAt": "2013-04-03T02:46:50Z",
"defaultBranch": "decaf",
"description": "Ruby in the browser.",
"fullName": "timimahoney/decaf",
"homepage": "http://trydecaf.org",
"language": "C++",
"name": "decaf",
"pushedAt": "2013-05-27T19:59:53Z",
"stargazersCount": 467,
"topics": [],
"updatedAt": "2025-11-04T04:04:14Z",
"url": "https://github.com/timimahoney/decaf"
}

Decaf is a modification of WebKit that runs Ruby in the browser. Use Ruby to access the DOM, work with the web standards, and even print to the inspector. Now, you can build an entire web application in Ruby instead of JavaScript.

To use Ruby in the browser, either download a binary or build it yourself.

<script type='text/ruby'>
window.onload do
introduction = document.create_element('p')
introduction.inner_text = 'Hello, world!'
document.body.append_child(introduction)
end
</script>

The same web platform APIs used by JavaScript are available in Ruby. If you’re not familiar with JavaScript and the DOM, then check out these resources:

There are a few major differences between the APIs in JavaScript and Ruby.

  • In Ruby, methods and attributes are specified in underscore_case instead of camelCase.
  • The window variable is accessible from only the top-most scope. Elsewhere you can use the global $window.
  • Ruby accepts Procs and blocks as callbacks and listeners. For example:
# Ruby with implicit blocks
$window.set_timeout(1000) { console.log('Hello!') }
$window.onload do |event|
console.log('The window loaded.')
end
# Ruby with explicit Procs
$window.set_timeout(Proc.new { console.log('Hello!') }, 1000)
$window.onload = Proc.new do |event|
console.log('The window loaded.')
end

If you find any problems, then please report them in the issues section.