Menu
CoddyTech
Course

Kotlin for Ruby Developers

Move from Ruby to Kotlin through null safety, collection ownership, functions, properties and object contracts. Compare blocks, collections and value models, build an order processor, and port a stock ledger.

Ruby and Kotlin side by side

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

  1. Strings and Templates

    Ruby double-quoted strings interpolate braced expressions after a hash sign; Kotlin uses dollar-prefixed names or braced expressions. Ruby puts and Kotlin println add line endings, but their handling of collections differs. Build the required text explicitly…

    Ruby
    1name="Ada"; puts "Hi "+name+" !"
    Kotlin
    1fun main(){2val ready=33println("Ready: $ready")4}
  2. Equality and Identity

    Ruby == is type-defined value equality, equal? checks identity, and eql? participates in Hash key comparison with hash. Kotlin == invokes null-safe equals while === checks identity. Strings compare contents, but ordinary classes default to identity and arrays…

    Ruby
    1a="ab";b="a"+"b";puts(a==b)
    Kotlin
    1fun main(){2val a=String(charArrayOf('t','e','a'))3val b=String(charArrayOf('t','e','a'))4println(a==b)5}
  3. Arrays and IntArray

    Ruby arrays can grow and accept negative indexes measured from the end. Kotlin arrays have fixed size and checked zero-based indexes; a negative index is invalid. IntArray uses primitive integer storage on the JVM. Use last or lastIndex to access the end and…

    Ruby
    1values=[2,4,6];puts values[-1]
    Kotlin
    1fun main(){2val a=intArrayOf(4,8,12)3println(a.last())4}
  4. While, Break, and Continue

    Ruby next skips the rest of an iteration and break exits traversal. Kotlin uses continue for skipping and break for termination, with Boolean conditions. Advance a manual cursor on every continuing path and check a sentinel before processing it. Do not…

    Ruby
    1n=3;while n>1;n-=1;end;puts n
    Kotlin
    1fun main(){2val kept=mutableListOf<String>()3for(word in listOf("tea","","STOP","coffee")){if(word=="STOP")break;if(word.isEmpty())continue;kept.add(word)}4println(kept.joinToString(","))5}
  5. Top-level Functions

    Ruby def creates methods, while lambdas and procs are callable objects with different control-flow rules. Kotlin supports top-level functions with typed parameters and result contracts. A non-Unit block body needs explicit returns; an expression body returns…

    Ruby
    1def hours(total);total/60;end;puts hours(125)
    Kotlin
    1fun isLong(text:String):Boolean = text.length>42fun main(){3println(isLong("coffee"))4}
  6. Input and String Formatting

    Ruby gets returns nil at EOF and chomp removes a line ending; Kotlin readlnOrNull returns null at EOF. Kotlin toInt requires a complete valid integer string, unlike Ruby to_i’s permissive prefix conversion. The task driver owns console I/O, so helpers return…

    Ruby
    1cents=305;puts format("tea: %d.%02d",cents/100,cents%100)
    Kotlin
    1fun main(){2println("  tea  ".trim().uppercase(java.util.Locale.ROOT))3}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Final Challenges

2 lessons

More courses for Ruby developers

Learn Kotlin from another language

Frequently asked questions

Who is Kotlin for Ruby Developers for?

For people who already write Ruby and want to learn Kotlin. Each lesson starts from Ruby you know and shows how Kotlin does the same thing, so you skip the beginner basics.

Do I need to know Kotlin already?

No. The course starts with your first Kotlin program. You need Ruby basics: variables, conditions, loops, functions and collections.

How many lessons does Kotlin for Ruby Developers have?

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

What does Kotlin for Ruby Developers cover?

The course is organized into chapters covering: Starting Kotlin, Values and Decisions, Collections and Ownership, Iteration and Transformations, and more.

Is Kotlin for Ruby 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 Kotlin for Ruby Developers for free

Get started