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.
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…
JavaScript1process.stdout.write("oak!");2// A comment3console.log("#seed");Ruby1print "oak!"2# A real comment3puts "#seed"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…
JavaScript1const wet = false;2const icon = wet ? "umbrella" : "sun";3console.log(icon);Ruby1wet = false2icon = if wet3 "umbrella"4else5 "sun"6end7puts iconArrays 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…
JavaScript1const values = [4, 8];2console.log(values.at(-1));3console.log(values[9] === undefined ? "missing" : values[9]);Ruby1values = [4, 8]2puts values[-1]3puts(values[9].nil? ? "missing" : values[9])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…
JavaScript1const values = [1, 2, 3];2const alias = values;3values.reverse();4console.log(alias.join(" "));Ruby1values = [1, 2, 3]2alias_values = values3values.reverse!4puts alias_values.join(" ")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…
JavaScript1const TextTools = { shout(text) { return text.toUpperCase(); } };2console.log(TextTools.shout("elm"));Ruby1module TextTools2 def self.shout(text)3 text.upcase4 end5end6puts TextTools.shout("elm")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…
JavaScript1class 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());Ruby1class 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 questionsStart with Ruby
8 lessonsFlow and Methods
6 lessonsCollections and Blocks
6 lessonsMutation and Errors
5 lessonsObjects and State
5 lessonsComposition and Dispatch
6 lessonsObjects in Practice
6 lessonsLending Desk Project
4 lessonsPort JavaScript Programs
2 lessonsFrequently 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.