Menu
CoddyTech
Course

Ruby for JavaScript Developers

Move from JavaScript to Ruby through 48 multi-file tasks covering flow, blocks, collections, errors, classes, modules and inheritance. Build a lending desk and port two complete source programs.

JavaScript and Ruby side by side

The same program in JavaScript and in Ruby, from the lessons of this course.

  1. Output and Comments

    JavaScript uses braces and semicolons or automatic semicolon insertion; Ruby uses end to close many constructs. Ruby line comments start with a hash sign, unlike JavaScript double-slash comments. Node console.log and Ruby puts add line endings…

    JavaScript
    1process.stdout.write("oak!");2// A comment3console.log("#seed");
    Ruby
    1print "oak!"2# A real comment3puts "#seed"
  2. Conditional Values

    JavaScript uses a ternary expression to select a value because an if statement is not an expression. Ruby if can itself return the selected branch value. Both languages evaluate only the chosen branch. Ruby elsif combines another condition into the same…

    JavaScript
    1const wet = false;2const icon = wet ? "umbrella" : "sun";3console.log(icon);
    Ruby
    1wet = false2icon = if wet3  "umbrella"4else5  "sun"6end7puts icon
  3. Arrays and Indexing

    JavaScript arrays can be sparse and reading an absent index yields undefined. Negative bracket indices are property names rather than positions from the end; at(-1) selects the last element. Ruby negative indices count from the end, and missing ordinary reads…

    JavaScript
    1const values = [4, 8];2console.log(values.at(-1));3console.log(values[9] === undefined ? "missing" : values[9]);
    Ruby
    1values = [4, 8]2puts values[-1]3puts(values[9].nil? ? "missing" : values[9])
  4. Mutation and Aliases

    JavaScript array reverse mutates, whereas Ruby reverse returns a new array and reverse! mutates. Both languages share object references on ordinary assignment. A JavaScript const reference may still point to a mutable array. Read method contracts rather than…

    JavaScript
    1const values = [1, 2, 3];2const alias = values;3values.reverse();4console.log(alias.join(" "));
    Ruby
    1values = [1, 2, 3]2alias_values = values3values.reverse!4puts alias_values.join(" ")
  5. Modules as Namespaces

    JavaScript ES modules have explicit imports and exports, while objects can group related functions at runtime. Ruby files do not automatically create namespaces; declare a module and load files with require_relative. A singleton method on a Ruby module…

    JavaScript
    1const TextTools = { shout(text) { return text.toUpperCase(); } };2console.log(TextTools.shout("elm"));
    Ruby
    1module TextTools2  def self.shout(text)3    text.upcase4  end5end6puts TextTools.shout("elm")
  6. Composing Objects

    JavaScript and Ruby store references to collaborator objects rather than cloning them automatically. Delegation calls an operation on a contained object and does not imply inheritance. Shared mutable collaborators can affect multiple owners, so decide whether…

    JavaScript
    1class Lens { label() { return "wide"; } }2class Camera {3  constructor(lens) { this.lens = lens; }4  label() { return this.lens.label(); }5}6console.log(new Camera(new Lens()).label());
    Ruby
    1class Lens2  def label; "wide"; end3end4class Camera5  def initialize(lens); @lens = lens; end6  def label; @lens.label; end7end8puts Camera.new(Lens.new).label

Syllabus

9 chapters48 lessons1 project48 challenges99 quiz questions

More courses for JavaScript developers

Learn Ruby from another language

Frequently asked questions

Who is Ruby for JavaScript Developers for?

For people who already write JavaScript and want to learn Ruby. Each lesson starts from JavaScript you know and shows how Ruby does the same thing, so you skip the beginner basics.

Do I need to know Ruby already?

No. The course starts with your first Ruby program. You need JavaScript basics: variables, conditions, loops, functions and collections.

How many lessons does Ruby for JavaScript Developers have?

Ruby for JavaScript Developers contains 48 interactive lessons you can complete at your own pace.

What does Ruby for JavaScript Developers cover?

The course is organized into chapters covering: Start with Ruby, Flow and Methods, Collections and Blocks, Mutation and Errors, and more.

Is Ruby for JavaScript Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start Ruby for JavaScript Developers for free

Get started