Ruby for Swift Developers
Move from Swift 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.
Swift and Ruby side by side
The same program in Swift and in Ruby, from the lessons of this course.
Output and Comments
Swift print and Ruby puts append a newline to ordinary text output, while each has ways to control exact formatting. Swift supports top-level executable code and compiled modules; Ruby executes source and loads neighboring files with require_relative. Keep…
Swift1let name = "Ada"2print("Hi, \(name)")Ruby1print "oak!"2# A real comment3puts "#seed"Conditional Values
Swift conditional expressions select a branch result, and Ruby if itself also produces a value. Swift requires Bool and applies static type rules, while Ruby conditions use truthiness. An unselected branch does not execute. Keep result values compatible with…
Swift1let wet=false2let label=wet ? "rain" : "sun"3print(label)Ruby1wet = false2icon = if wet3 "umbrella"4else5 "sun"6end7puts iconArrays and Indexing
Swift arrays are zero-based and direct invalid indexing traps; last returns an optional. Ruby ordinary missing reads return nil and negative indexes count from the end. Check Swift indices before access and use Ruby fetch when absence should raise. A forced…
Swift1let values=[4,8]2print(values.last!)3print(values.indices.contains(9) ? String(values[9]) : "missing")Ruby1values = [4, 8]2puts values[-1]3puts(values[9].nil? ? "missing" : values[9])Mutation and Aliases
Swift Array and Dictionary have value semantics, commonly implemented with copy-on-write, so assigning then modifying a copy preserves the original. Ruby assignment shares a mutable array object; reverse! changes what aliases observe while reverse returns…
Swift1let a = ["n": 1]2var b = a3b["n"] = 94print(a["n"]!)Ruby1values = [1, 2, 3]2alias_values = values3values.reverse!4puts alias_values.join(" ")Modules as Namespaces
Swift modules, imports and namespace-like types organize compiled declarations. Ruby modules group constants and methods at runtime, while require_relative loads neighboring source files. A Ruby filename creates no namespace automatically. Ruby include…
Swift1enum Pricing { static func cost(_ n: Int) -> Int { n * 2 } }2print(Pricing.cost(3))Ruby1module TextTools2 def self.shout(text)3 text.upcase4 end5end6puts TextTools.shout("elm")Composing Objects
Swift composition may retain class references or copy value collaborators, while Ruby instance variables retain object references. Delegation supports variation without inheritance. Swift protocols constrain collaborators statically; Ruby commonly invokes…
Swift1struct Policy { let factor: Int; func apply(_ n: Int) -> Int { n * factor } }2struct Order { let policy: Policy; func total(_ n: Int) -> Int { policy.apply(n) } }3print(Order(policy: Policy(factor: 2)).total(3))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 Swift Programs
2 lessonsFrequently asked questions
Who is Ruby for Swift Developers for?
For people who already write Swift and want to learn Ruby. Each lesson starts from Swift 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 Swift basics: variables, conditions, loops, functions and collections.
How many lessons does Ruby for Swift Developers have?
Ruby for Swift Developers contains 48 interactive lessons you can complete at your own pace.
What does Ruby for Swift 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 Swift Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.