Menu
CoddyTech
Course

Ruby for Go Developers

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

Go and Ruby side by side

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

  1. Output and Comments

    Go starts a command in main and fmt.Println appends a newline; Ruby executes top-level statements and puts prints ordinary text with a newline. Go imports compile package dependencies, while Ruby require_relative loads neighboring source files at runtime.…

    Go
    1package main2import ("fmt")3
    4func main(){5fmt.Println("Hi"+", Ada")6}
    Ruby
    1print "oak!"2# A real comment3puts "#seed"
  2. Conditional Values

    Go if is a statement and there is no ternary conditional operator, so branches or helpers commonly assign a result. Ruby if itself is an expression and returns the selected branch’s value. Ruby also supports postfix conditionals. Go requires boolean…

    Go
    1package main2import ("fmt")3
    4func main(){5wet:=false;label:="sun";if wet{label="rain"};fmt.Println(label)6}
    Ruby
    1wet = false2icon = if wet3  "umbrella"4else5  "sun"6end7puts icon
  3. Arrays and Indexing

    Go slices grow through append, and invalid indexing panics. Ruby arrays grow dynamically, ordinary missing reads return nil and negative indexes count from the end. Go uses len minus one for a nonempty slice’s final element instead of negative indexing. Use…

    Go
    1package main2import ("fmt")3
    4func main(){5values:=[]int{4,8};fmt.Println(values[len(values)-1]);if len(values)>9{fmt.Println(values[9])}else{fmt.Println("missing")}6}
    Ruby
    1values = [4, 8]2puts values[-1]3puts(values[9].nil? ? "missing" : values[9])
  4. Mutation and Aliases

    Go slice assignment copies a descriptor that can share the same backing array; copy into newly allocated storage gives independent outer elements. Ruby array assignment also aliases storage through the object reference. Ruby reverse! mutates while reverse…

    Go
    1package main2import ("fmt")3
    4func main(){5a:=[]int{1}; b:=make([]int,len(a)); copy(b,a); b[0]=9; fmt.Println(a[0])6}
    Ruby
    1values = [1, 2, 3]2alias_values = values3values.reverse!4puts alias_values.join(" ")
  5. Modules as Namespaces

    Go packages group compiled declarations, and imports load dependencies through the build rather than evaluating an arbitrary source file at a call site. Ruby require_relative loads files at runtime and modules explicitly group constants and methods. A…

    Go
    1package main2import ("fmt")3func subtotal(price,quantity int)int{return price*quantity}4func main(){5fmt.Println(subtotal(4,3))6}
    Ruby
    1module TextTools2  def self.shout(text)3    text.upcase4  end5end6puts TextTools.shout("elm")
  6. Composing Objects

    Go structs can contain values, pointers or interface-valued collaborators, with different copying and sharing behavior. Ruby instance variables retain object references without cloning them. Go interfaces are satisfied implicitly by method sets; Ruby commonly…

    Go
    1package main2import ("fmt")3type Policy interface {Apply(int)int}4type DoublePolicy struct{}5func(DoublePolicy) Apply(n int)int{return n*2}6type Order struct{Policy Policy}7func(o Order) Total()int{return o.Policy.Apply(3)}8func main(){9order:=Order{Policy:DoublePolicy{}}; fmt.Println(order.Total())10}
    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 Go developers

Learn Ruby from another language

Frequently asked questions

Who is Ruby for Go Developers for?

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

How many lessons does Ruby for Go Developers have?

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

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

Get started