Dart for Ruby Developers
Move from Ruby to standalone Dart through typed functions, null safety, collections, errors and object contracts. Build a four-step parcel depot, use classes, interfaces and mixins, then port two complete Ruby programs.
Ruby and Dart side by side
The same program in Ruby and in Dart, from the lessons of this course.
Output and Comments
Ruby interpolates expressions with #{...} inside double-quoted strings. Dart uses dollar-prefixed names or braces inside ordinary strings, including single-quoted ones. Ruby puts and Dart print both end these String outputs with a newline; Ruby scripts run…
Ruby1lane = 32puts "lane:#{lane}"Dart1void main(){final lane=3;print('lane:$lane');}Boolean Conditions
Ruby treats only nil and false as false; zero and the empty String are true. Its && and || return operand values, while Dart requires bool operands and produces bool results. Both short-circuit, so a right-hand call with visible output can be skipped entirely.
Ruby1def probe2 puts 'probe'3 true4end5if false && probe6 puts 'open'7else8 puts 'closed'9endDart1bool probe(){print('probe');return true;}2void main(){if(false && probe()){print('open');}else{print('closed');}}Functions and Returns
Ruby methods return their last evaluated expression unless return exits earlier. Ordinary Ruby signatures do not declare result types. Dart block bodies need an explicit return for a value, while an arrow body abbreviates one returned expression. Non-nullable…
Ruby1def is_log(name)2 name.end_with?('.log')3end4puts is_log('server.log')Dart1bool isLog(String name)=>name.endsWith('.log');2void main(){print(isLog('server.log'));}Iterables and Laziness
Ruby Array.map evaluates its block eagerly; lazy.map on an Enumerator::Lazy defers work until values are requested. Dart map normally returns a lazy Iterable. Repeated Dart traversals can run callbacks again, so materialize with toList when you need a stable…
Ruby1result = [2, 3].map do |n|2 puts "visit:#{n}"3 n * 24end5puts 'made'6puts result.firstDart1void main(){final result=[2,3].map((n){print('visit:$n');return n*2;});print('made');print(result.first);}Parsing and Validation
Ruby String#to_i accepts a numeric prefix and can return zero for invalid text. Integer with exception: false returns nil on failure, but its accepted grammar may still be broader than a strict business format. Dart int.tryParse returns null. Keep syntax…
Ruby1puts(Integer('nope', 10, exception: false) || 'invalid')2puts Integer('42', 10, exception: false)Dart1void main(){print(int.tryParse('nope')??'invalid');print(int.tryParse('42'));}Classes and Instances
Ruby instance variables use @ names and can be created when assigned; accessor methods expose them to callers. Dart fields and method types are declared in the class, and this is implicit inside methods. Both new Ruby instances and newly constructed Dart…
Ruby1class Lamp2 attr_reader :on3 def initialize; @on = false; end4 def toggle; @on = !@on; end5end6a, b = Lamp.new, Lamp.new7a.toggle8puts "#{a.on}:#{b.on}"Dart1class Lamp{bool on=false;void toggle(){on=!on;}}2void main(){final a=Lamp(),b=Lamp();a.toggle();print('${a.on}:${b.on}');}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFirst Dart Programs
6 lessonsFlow and Decisions
5 lessonsFunctions and Values
6 lessonsCollection Pipelines
6 lessonsParsing and Failures
3 lessonsObjects and State
6 lessonsContracts and Reuse
7 lessonsEquality and Testing
3 lessonsParcel Depot Project
4 lessonsFinal Source Ports
2 lessonsFrequently asked questions
Who is Dart for Ruby Developers for?
For people who already write Ruby and want to learn Dart. Each lesson starts from Ruby you know and shows how Dart does the same thing, so you skip the beginner basics.
Do I need to know Dart already?
No. The course starts with your first Dart program. You need Ruby basics: variables, conditions, loops, functions and collections.
How many lessons does Dart for Ruby Developers have?
Dart for Ruby Developers contains 48 interactive lessons you can complete at your own pace.
What does Dart for Ruby Developers cover?
The course is organized into chapters covering: First Dart Programs, Flow and Decisions, Functions and Values, Collection Pipelines, and more.
Is Dart 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.