Menu
CoddyTech
Course

Ruby for C# Developers

Move from C# 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.

C# and Ruby side by side

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

  1. Output and Comments

    C# Console.WriteLine and Ruby puts both append a newline to ordinary text output. C# programs compile with an entry point, including one generated for top-level statements; Ruby executes top-level statements directly and loads neighboring files with…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text.RegularExpressions;5Console.WriteLine("Hi" + ", Ada");
    Ruby
    1print "oak!"2# A real comment3puts "#seed"
  2. Conditional Values

    C# if is a statement while the conditional operator selects a value. Ruby if itself is an expression whose chosen branch supplies the result, and postfix conditional statements are also available. Ruby conditions accept objects, with only false and nil…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4bool wet=false;string label=wet?"rain":"sun";Console.WriteLine(label);
    Ruby
    1wet = false2icon = if wet3  "umbrella"4else5  "sun"6end7puts icon
  3. Arrays and Indexing

    C# arrays have fixed length and checked indexes, while List grows dynamically. Ruby arrays grow and ordinary out-of-bounds reads return nil. Ruby negative indexes count from the end; C# uses explicit index-from-end syntax such as ^1 where supported. Use Ruby…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4int[] values={4,8};Console.WriteLine(values[^1]);5Console.WriteLine(values.Length>9?values[9].ToString():"missing");
    Ruby
    1values = [4, 8]2puts values[-1]3puts(values[9].nil? ? "missing" : values[9])
  4. Mutation and Aliases

    C# List is a reference type, so assignment aliases the same mutable list, as Ruby array assignment does. C# structs instead have value-copy semantics that should not be generalized to all objects. Ruby reverse! mutates shared state while reverse returns a new…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4var values=new List<int>{1,2,3};var alias=values;values.Reverse();Console.WriteLine(string.Join(" ",alias));
    Ruby
    1values = [1, 2, 3]2alias_values = values3values.reverse!4puts alias_values.join(" ")
  5. Modules as Namespaces

    C# namespaces and using directives resolve names in compiled code; using a namespace does not execute a source file. Ruby modules organize constants and methods at runtime, with require_relative loading neighboring files. A Ruby filename does not create a…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4Console.WriteLine(TextTools.Words.Shout("elm"));5namespace TextTools {static class Words {public static string Shout(string text)=>text.ToUpperInvariant();}}
    Ruby
    1module TextTools2  def self.shout(text)3    text.upcase4  end5end6puts TextTools.shout("elm")
  6. Composing Objects

    C# class fields and Ruby instance variables can retain references to collaborators without cloning them. C# interfaces specify nominal contracts, while Ruby commonly invokes compatible methods dynamically. Delegation allows behavior to vary without…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text.RegularExpressions;5var order=new Order(new DoublePolicy()); Console.WriteLine(order.Total());6interface IPolicy {int Apply(int n);}7class DoublePolicy:IPolicy {public int Apply(int n)=>n*2;}8class Order {private IPolicy policy; public Order(IPolicy p){policy=p;} public int Total()=>policy.Apply(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 C# developers

Learn Ruby from another language

Frequently asked questions

Who is Ruby for C# Developers for?

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

How many lessons does Ruby for C# Developers have?

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

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

Get started