Ruby 2 JavaScript

CoffeeScript

CoffeeScript is a programming language that transcompiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python and Haskell in an effort to enhance JavaScript’s brevity and readability.

Quick CoffeeScript Review

Here a quick how to if CoffeeScript in general

  • Install CoffeScript lib

    1. npm install -g coffee-script
  • For live conversion

    1. coffee --watch --compile script.coffee

Ruby CoffeScript gem

Ruby CoffeeScript gem is a bridge to the official CoffeeScript compiler.

  • Install CoffeeScript gem

    1. gem install coffee-script
  • Convert CoffeeScript file to JavaScript

  1. #!/usr/bin/env ruby
  2. require 'coffee-script'
  3. if ARGF
  4. file = File.open("#{ARGV[0]}.js", 'a')
  5. file.write CoffeeScript.compile(ARGF.read)
  6. end

Run it

  1. ruby coffee2js.rb exploit.coffee

Opal

Opal is a Ruby to JavaScript source-to-source compiler. It also has an implementation of the Ruby corelib.

  • Install Opal gem
    1. gem install opal opal-jquery