Menu
CoddyTech
Course

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.

  1. 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…

    Swift
    1let name = "Ada"2print("Hi, \(name)")
    Ruby
    1print "oak!"2# A real comment3puts "#seed"
  2. 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…

    Swift
    1let wet=false2let label=wet ? "rain" : "sun"3print(label)
    Ruby
    1wet = false2icon = if wet3  "umbrella"4else5  "sun"6end7puts icon
  3. Arrays 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…

    Swift
    1let values=[4,8]2print(values.last!)3print(values.indices.contains(9) ? String(values[9]) : "missing")
    Ruby
    1values = [4, 8]2puts values[-1]3puts(values[9].nil? ? "missing" : values[9])
  4. 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…

    Swift
    1let a = ["n": 1]2var b = a3b["n"] = 94print(a["n"]!)
    Ruby
    1values = [1, 2, 3]2alias_values = values3values.reverse!4puts alias_values.join(" ")
  5. 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…

    Swift
    1enum Pricing { static func cost(_ n: Int) -> Int { n * 2 } }2print(Pricing.cost(3))
    Ruby
    1module TextTools2  def self.shout(text)3    text.upcase4  end5end6puts TextTools.shout("elm")
  6. 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…

    Swift
    1struct 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))
    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 Swift developers

Learn Ruby from another language

Frequently 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.

Coddy programming languages illustration

Start Ruby for Swift Developers for free

Get started