Opal 0.9: direct JS calls, console.rb, numeric updates, better reflection, and fixes aplenty

Opal is now officially on the 0.9.x release path, having just released 0.9.2. Thanks to all the contributors to Opal, especially over the holidays, and we're excited for what the new year will bring to the Opal community. Some highlights from the latest release:

Direct calling of JavaScript methods

You can now make direct JavaScript method calls on native JS objects using the recv.JS.method syntax. Has support for method calls, final callback (as a block), property getter and setter (via #[] and #[]=), splats, JavaScript keywords (via the ::JS module) and global functions (after require "js").

Some examples, first a simple method call:

# javascript: foo.bar()
foo.JS.bar
foo.JS.bar()

Arguments just like Ruby, with or without parentheses:

# JavaScript: foo.bar(1, "a")
foo.JS.bar(1, :a)
foo.JS.bar 1, :a

Argument splats (doesn't that Ruby just look great?):

# JavaScript: ($a = foo).bar.apply($a, [1].concat([2, 3]))
foo.JS.bar(1, *[2, 3])
foo.JS.bar 1, *[2, 3]

Properties work too!

# JavaScript: foo["bar"]
foo.JS[:bar]

# JavaScript: fooarr[2]
fooarr.JS[2]

That's just the beginning, and should prove to be a great new way to write down-to-JS-level code without interrupting the flow of your Ruby code. Read the in-depth documentation here (scroll down to the Calling JavaScript Methods section).

Console wrapper added to the stdlib

Requiring the new console wrapper will make available the $console global variable. Check out the docs here. Example:

require 'console'
$console.log a: 1, b: {c: 3}

Note: Be advised that Kernel#pp no longer forwards arguments directly to console.log.

Updates to Numeric, Complex, and Rational

Numeric semantics are now compliant with Ruby, and both Complex and Rational have been fully implemented.

Better reflection, exception handling, and method_missing-powered operators

Some updates to Ruby reflection support to allow for deeper metaprogramming abilities. These all are now working: method_added, method_removed, method_undefined, singleton_method_added, singleton_method_removed and singleton_method_undefined.

Improvements to exception handling as well: Exception#exception, Exception::exception, Exception#message, and Exception#to_s are fully implemented.

Operator methods (e.g. +, <, etc.) can be handled by method_missing. Note: always be aware of possible performance penalties when not using Opal's optimized operators.

Bug fixes and more!

As always, Opal 0.9.2 includes many bug fixes and improvements to the internals of the Opal libraries, so be sure to read the changelog for further details (as well as information on changes throughout the 0.8.x releases if you didn't see those previously).