OPAL - RUBY STYLE
RUBY IN THE BROWSER
    Forrest Chang, OCRuby
TRENDS
NODE.JS
NOV 2011
MOST POPULAR REPO ON
       GITHUB
JAVASCRIPT REVOLUTION
JS EVERYWHERE
IDEA: TAKE THE FRONTEND
LANGUAGE PUT IT THE BACK
            END
GOOD IDEA?
LANGUAGES THAT COMPILE
    TO JAVASCRIPT
JUST A FEW..
I GET THE IDEA PEOPLE
MIGHT PREFER SOMETHING
 OTHER THAN JAVASCRIPT
IDEA: TAKE THE BACKEND
LANGUAGE, PUT IT ON THE
        FRONT END
APPARENTLY A POPULAR
        IDEA
Coffeescript
WHY
Better syntax

Less verbose, clearer, more intention

Some nice features, list comprehensions, implicit
return, etc.

Happier programmers *
Y U NO COFFEESCRIPT?
NOTHING WRONG WITH IT
BUT I LIKE RUBY BETTER
AND ALREADY WORK RUBY
   ON THE BACKEND
BUT IF YOU’RE GOING TO
CHANGE THE SYNTAX, WHY
   NOT ALL THE WAY?
HASN’T IT BEEN TRIED
     BEFORE?
active
active
active
active Less ruby like
active
WHAT IS OPAL
RUNTIME?
USED TO BOTHER ME, MIGHT
 BOTHER ME AGAIN LATER
JAVASCRIPT IS NOW THE “C
      OF THE WEB”
DO PEOPLE CARE THAT
RUBY/LISP/PYTHON DOESN’T
    LOOK/ACT LIKE C
AS LONG AS IT’S DONE WELL
EMBRACE THE
ABSTRACTION!
HTTPS://GITHUB.COM/OPAL

  opalscript
  Javascript + Ruby = OpalScript (Sssh, It's a secret and not
  ready yet).                                                   • opal-spec
  Last updated 14 hours ago                                       Spec Library for opal
                                                                  Last updated 23 days ago
• opal
  Ruby runtime and library on top of Javascript                 • opal-rails
  Last updated 14 hours ago                                       Rails bindings for Opal JS engine
                                                                  Last updated a month ago
• opal-jquery
  Give opal access to jquery
  Last updated 15 hours ago
                                                                  • opal-erb
• opal-todos                                                          ERB parser and runtime for opal
                                                                      Last updated a month ago
  todomvc based opal example
  Last updated 3 days ago
                                                                • vienna
• opal-node                                                       Client-side MVC framework for Opal
                                                                  Last updated a month ago
  Coffescript was so cool…
  Last updated 3 days ago


• opal.github.com
  Opal Website
  Last updated 7 days ago
I HAD A SIMILAR IDEA
CHAI-SCRIPT

Hot drink motif. What drink is reddish?

Ruby equivalent of Coffeescript

Syntactic sugar, but ruby flavor

eventd subset of ruby w/idea of eventd gems for front
and backend

Ease ‘em into ruby
OPALSCRIPT


Likely the same idea

1st public commits just released on 10/24/2012 (i.e.
yesterday)

I’ll be keeping a key eye on this, not certain which I’ll
prefer
MY DRIVER
MATZ PRINCIPLE
MAKE THE PROGRAMMER
       HAPPY
I.E. ME
I’M ENJOYING IT THUS FAR
A NEAT IDEA - TRY OPAL
An example: bit.ly/WFHLyh
CODE
modules to share functionality
modules to share functionality
wrapping js via x string
modules to share functionality
      wrapping js via x string

Easy classes
modules to share functionality
     wrapping js via x string

Easy classes
     include module
modules to share functionality
      wrapping js via x string

Easy classes
     include module
      easy attributes
modules to share functionality
      wrapping js via x string

Easy classes
     include module
      easy attributes



                calling my js wrapper
modules to share functionality
      wrapping js via x string

Easy classes
     include module
      easy attributes



                calling my js wrapper

    Inheritance, baby
modules to share functionality
       wrapping js via x string

 Easy classes
      include module
       easy attributes



                 calling my js wrapper

     Inheritance, baby

super, baby
modules to share functionality
       wrapping js via x string

 Easy classes
      include module
       easy attributes



                 calling my js wrapper

     Inheritance, baby

super, baby

     reusing JsUtils again...
COMPILED JS PRETTY
STRAIGHT FORWARD
BUT VERBOSE
Opal runtime
Opal runtime
matching line of code
Opal runtime
         matching line of code
JsUtils module
Opal runtime
         matching line of code
JsUtils module

             js alert wrapped
Opal runtime
         matching line of code
JsUtils module

             js alert wrapped




Dude class
Gal class
Gal class




     super
Gal class




     super


             Bystander class
Gal class




     super


             Bystander class




                 Instance invocations
WHAT’S TO LIKE?


Ruby

Rake

Rspec

nicer APIs

Ruby on the backend, Ruby on the frontend
RUBY EVERYWHERE!
Desktop/Server: MRI, JRuby, Iron Ruby, Rubinius

Faster Rubylike subset for JVM (Android and other
possibilities) Mirah

Embedded: mruby

IOS: RubyMotion

Browser/Node: opal
YOU KNOW WHAT I MEAN?
CODE ALONG
opal

opal-rails

opal-jquery

opal filter in haml

follow the gist https://gist.github.com/3956417
Opal - Ruby Style!!  Ruby in the browser

Opal - Ruby Style!! Ruby in the browser