Menu
CoddyTech
Course

Ruby for Rust Developers

Move from Rust 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.

Rust and Ruby side by side

The same program in Rust and in Ruby, from the lessons of this course.

  1. Output and Comments

    Rust println! formats text and appends a newline, while Ruby puts prints ordinary text with a newline. Rust starts in main and compiles modules; Ruby executes top-level statements and loads neighboring files with require_relative. Keep reusable methods…

    Rust
    1fn main() {2println!("Hi, {}", "Ada");3}
    Ruby
    1print "oak!"2# A real comment3puts "#seed"
  2. Conditional Values

    Rust if and Ruby if can both produce a selected branch value. Rust requires bool conditions and compatible expression types, while Ruby uses truthiness and determines operations dynamically. Ruby can yield nil when no branch matches. Keep branch results…

    Rust
    1
    2fn main(){3let wet=false;let label=if wet{"rain"}else{"sun"};println!("{}",label);4}
    Ruby
    1wet = false2icon = if wet3  "umbrella"4else5  "sun"6end7puts icon
  3. Arrays and Indexing

    Rust arrays and Vec use zero-based indexes; direct invalid indexing panics while get returns Option. Ruby ordinary missing reads return nil and negative indexes count from the end. Rust uses last or a valid unsigned index instead. Choose Ruby fetch when…

    Rust
    1
    2fn main(){3let values=[4,8];println!("{}",values.last().unwrap());println!("{}",values.get(9).map_or("missing".to_owned(),|v|v.to_string()));4}
    Ruby
    1values = [4, 8]2puts values[-1]3puts(values[9].nil? ? "missing" : values[9])
  4. Mutation and Aliases

    Assigning a Rust Vec moves ownership unless it is borrowed or cloned, and cloning a Vec of integers creates independent storage. Ruby array assignment aliases the same object; reverse! mutates while reverse returns another array. Rust borrowing protects…

    Rust
    1fn main() {2let a=vec![1]; let mut b=a.clone(); b[0]=9; println!("{}",a[0]);3}
    Ruby
    1values = [1, 2, 3]2alias_values = values3values.reverse!4puts alias_values.join(" ")
  5. Modules as Namespaces

    Rust modules and use organize compiled names and visibility; they do not evaluate source into a runtime object. Ruby require_relative loads neighboring files while a declared module groups constants and methods. A filename creates no namespace automatically.…

    Rust
    1mod pricing {pub fn subtotal(price:i32,quantity:i32)->i32 {price*quantity}}2fn main() {3println!("{}",pricing::subtotal(4,3));4}
    Ruby
    1module TextTools2  def self.shout(text)3    text.upcase4  end5end6puts TextTools.shout("elm")
  6. Composing Objects

    Rust structs own or borrow collaborators explicitly, with lifetimes and traits describing requirements. Ruby instance variables retain references without transferring exclusive ownership or cloning the child. Delegation provides flexible behavior without…

    Rust
    1struct Policy{factor:i32}2impl Policy{fn apply(&self,n:i32)->i32{n*self.factor}}3struct Order{policy:Policy}4impl Order{fn total(&self,n:i32)->i32{self.policy.apply(n)}}5fn main() {6let order=Order{policy:Policy{factor:2}}; println!("{}",order.total(3));7}
    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 Rust developers

Learn Ruby from another language

Frequently asked questions

Who is Ruby for Rust Developers for?

For people who already write Rust and want to learn Ruby. Each lesson starts from Rust 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 Rust basics: variables, conditions, loops, functions and collections.

How many lessons does Ruby for Rust Developers have?

Ruby for Rust Developers contains 48 interactive lessons you can complete at your own pace.

What does Ruby for Rust 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 Rust 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 Rust Developers for free

Get started