Ruby for Lua Developers
Move from Lua 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.
Lua and Ruby side by side
The same program in Lua and in Ruby, from the lessons of this course.
Output and Comments
Lua uses double-hyphen comments and end to close many constructs. Ruby also uses end, but a hash sign begins its line comments. Lua print separates multiple arguments and adds a newline; io.write does not. Ruby puts and print have their own formatting…
Lua1io.write("oak!")2-- A comment3print("#seed")Ruby1print "oak!"2# A real comment3puts "#seed"Conditional Values
Lua uses if, elseif, else and end as statement syntax. Ruby if can also produce a value from its selected branch. Lua has no built-in ternary operator, so an explicit local assignment is often safer than an and/or idiom when false or nil are valid results.…
Lua1local wet = false2local icon3if wet then icon = "umbrella" else icon = "sun" end4print(icon)Ruby1wet = false2icon = if wet3 "umbrella"4else5 "sun"6end7puts iconArrays and Indexing
Lua sequences conventionally start at one, while Ruby arrays start at zero. Lua negative table keys are ordinary keys; Ruby negative indices count from the end. Missing table lookups and ordinary missing Ruby array reads both yield nil. Lua sequence length is…
Lua1local values = {4, 8}2print(values[#values])3print(values[9] == nil and "missing" or values[9])Ruby1values = [4, 8]2puts values[-1]3puts(values[9].nil? ? "missing" : values[9])Mutation and Aliases
Lua table assignment and Ruby array assignment share the referenced mutable object. Lua strings remain immutable, unlike ordinary Ruby strings. Ruby method names ending in an exclamation mark often indicate a destructive alternative, but many mutators have no…
Lua1local values = {1, 2, 3}2local alias = values3values[1], values[3] = values[3], values[1]4print(table.concat(alias, " "))Ruby1values = [1, 2, 3]2alias_values = values3values.reverse!4puts alias_values.join(" ")Modules as Namespaces
Lua modules commonly return a table of operations. Ruby modules explicitly group names, and require_relative loads the file rather than wrapping it in a namespace automatically. Lua require caches loaded modules by module name; Ruby require also avoids…
Lua1local TextTools = {}2function TextTools.shout(text) return string.upper(text) end3print(TextTools.shout("elm"))Ruby1module TextTools2 def self.shout(text)3 text.upcase4 end5end6puts TextTools.shout("elm")Composing Objects
Lua tables can store other tables as collaborators, sharing them rather than cloning them. Ruby objects likewise store references to child objects. Composition delegates a responsibility without requiring inheritance. If a collaborator is mutable and shared…
Lua1local lens = {label = function(self) return "wide" end}2local camera = {lens = lens}3function camera:label() return self.lens:label() end4print(camera: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 Lua Programs
2 lessonsFrequently asked questions
Who is Ruby for Lua Developers for?
For people who already write Lua and want to learn Ruby. Each lesson starts from Lua 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 Lua basics: variables, conditions, loops, functions and collections.
How many lessons does Ruby for Lua Developers have?
Ruby for Lua Developers contains 48 interactive lessons you can complete at your own pace.
What does Ruby for Lua 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 Lua Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.