Ruby for GDScript Developers
Move from GDScript 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.
GDScript and Ruby side by side
The same program in GDScript and in Ruby, from the lessons of this course.
Output and Comments
GDScript uses indentation for blocks and a hash sign for comments; Ruby commonly closes blocks and definitions with end. A hash sign inside a quoted string remains data in both examples. Godot executes lifecycle callbacks, while Ruby runs top-level statements…
GDScript1extends SceneTree2 3func _init():4 var name = "Mira"5 # Preserve the space after the comma.6 print("Hello, " + name + "!")7 quit()Ruby1print "oak!"2# A real comment3puts "#seed"Conditional Values
GDScript uses value_if_true if condition else value_if_false for a conditional expression. Ruby if itself yields the selected branch value and also supports postfix conditional statements. Ruby truthiness differs for zero and empty containers, so carry over…
GDScript1extends SceneTree2 3func _init():4 var wet = false5 var label = "rain" if wet else "sun"6 print(label)7 quit()Ruby1wet = false2icon = if wet3 "umbrella"4else5 "sun"6end7puts iconArrays and Indexing
GDScript Array and Ruby Array both allow negative indexing to count from the end. Their missing-index behavior differs: Ruby ordinary reads return nil, while invalid GDScript access raises an engine error. Use Ruby fetch when absence should raise, or guard…
GDScript1extends SceneTree2 3func _init():4 var values = [4, 8]5 print(values[-1])6 print(values[9] if values.size() > 9 else "missing")7 quit()Ruby1values = [4, 8]2puts values[-1]3puts(values[9].nil? ? "missing" : values[9])Mutation and Aliases
GDScript arrays and dictionaries are reference containers; assignment shares them and duplicate normally copies only the outer container. Ruby assignment similarly aliases objects, while reverse! mutates an array and reverse makes another outer array. The…
GDScript1extends SceneTree2func _init():3 var original = {"count": 2, "items": ["key"]}4 var copied = original.duplicate()5 copied["count"] = 96 copied["items"].append("map")7 print(str(original["count"]) + ":" + str(copied["count"]) + ":" + str(original["items"].size()))8 quit()Ruby1values = [1, 2, 3]2alias_values = values3values.reverse!4puts alias_values.join(" ")Modules as Namespaces
GDScript load and preload obtain script resources, and class_name registers a class for named use; inner classes can organize helpers. Ruby require_relative loads a neighboring file, but the filename creates no namespace automatically. Declare a Ruby module…
GDScript1extends SceneTree2class Pricing:3 static func subtotal(price, quantity):4 return price * quantity5func _init():6 print(Pricing.subtotal(6, 3))7 quit()Ruby1module TextTools2 def self.shout(text)3 text.upcase4 end5end6puts TextTools.shout("elm")Composing Objects
GDScript and Ruby can retain collaborators by reference and delegate calls to them. Assignment does not clone a child or transfer exclusive ownership. GDScript static annotations can constrain a collaborator, while dynamic calls and Ruby duck typing rely on…
GDScript1extends SceneTree2class Policy:3 var factor4 func _init(value):5 factor = value6 func apply(n):7 return n * factor8class Model:9 var policy10 func _init(chosen_policy):11 policy = chosen_policy12 func total(n):13 return policy.apply(n)14func _init():15 var model = Model.new(Policy.new(4))16 print(model.total(3))17 quit()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 GDScript Programs
2 lessonsFrequently asked questions
Who is Ruby for GDScript Developers for?
For people who already write GDScript and want to learn Ruby. Each lesson starts from GDScript 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 GDScript basics: variables, conditions, loops, functions and collections.
How many lessons does Ruby for GDScript Developers have?
Ruby for GDScript Developers contains 48 interactive lessons you can complete at your own pace.
What does Ruby for GDScript 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 GDScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.