Menu
CoddyTech
Course

Ruby for Python Developers

Move from Python to Ruby through 48 multi-file tasks covering control flow, blocks, collections, errors, classes, modules and inheritance. Build a lending desk and port two complete Python programs.

Python and Ruby side by side

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

  1. Output and Comments

    Python uses indentation for suites; Ruby commonly closes definitions and control structures with end. Both allow a hash sign to start a line comment outside a string. Ruby puts adds a newline, while print does not. A hash sign inside quotes remains data. In…

    Python
    1print("oak", end="!")2# A real comment3print("#seed")
    Ruby
    1print "oak!"2# A real comment3puts "#seed"
  2. Conditional Values

    Python conditional expressions place the result before the condition. Ruby if can itself produce a value, with the selected branch providing the result. Use elsif for another branch and close the construct with end. Ruby also offers unless for a negative…

    Python
    1wet = False2icon = "umbrella" if wet else "sun"3print(icon)
    Ruby
    1wet = false2icon = if wet3  "umbrella"4else5  "sun"6end7puts icon
  3. Arrays and Indexing

    Python lists and Ruby arrays hold ordered references and allow negative indexing. Their out-of-bounds behavior differs: ordinary Ruby array indexing returns nil, while Python indexing raises IndexError. Ruby fetch raises IndexError unless a fallback is…

    Python
    1values = [4, 8]2print(values[-1])3print(values[9] if len(values) > 9 else "missing")
    Ruby
    1values = [4, 8]2puts values[-1]3puts(values[9].nil? ? "missing" : values[9])
  4. Mutation and Aliases

    Assignment shares object references in both languages. Replacing a local binding differs from mutating the referenced object, which aliases can observe. Ruby arrays and strings are mutable unless frozen; Python lists are mutable but strings are not. The…

    Python
    1values = [1, 2, 3]2alias = values3values.reverse()4print(" ".join(map(str, alias)))
    Ruby
    1values = [1, 2, 3]2alias_values = values3values.reverse!4puts alias_values.join(" ")
  5. Modules as Namespaces

    Python files create module namespaces. A Ruby file does not automatically wrap its definitions in a namespace: require_relative loads it, while a module declaration groups constants and methods explicitly. A module can serve as a namespace or later be…

    Python
    1class TextTools:2    @staticmethod3    def shout(text):4        return text.upper()5print(TextTools.shout("elm"))
    Ruby
    1module TextTools2  def self.shout(text)3    text.upcase4  end5end6puts TextTools.shout("elm")
  6. Composing Objects

    Both Python and Ruby compose objects by storing references to collaborators. A containing object does not automatically clone or exclusively own a supplied child. If two containers share one mutable child, either can observe changes to it. Composition allows…

    Python
    1class Lens:2    def label(self):3        return "wide"4class Camera:5    def __init__(self, lens):6        self.lens = lens7    def label(self):8        return self.lens.label()9print(Camera(Lens()).label())
    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 Python developers

Learn Ruby from another language

Frequently asked questions

Who is Ruby for Python Developers for?

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

How many lessons does Ruby for Python Developers have?

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

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

Get started