Ruby for Dart Developers
Move from Dart 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.
Dart and Ruby side by side
The same program in Dart and in Ruby, from the lessons of this course.
Output and Comments
Dart begins in main and print adds a newline; Ruby runs top-level statements and puts similarly prints ordinary text with a newline. Ruby require_relative loads neighboring source files, while Dart imports declare library dependencies. Keep the entry point’s…
Dart1 2void main() {3print("Hi" + ", Ada");4}Ruby1print "oak!"2# A real comment3puts "#seed"Conditional Values
Dart if is a statement and the conditional operator selects a value. Ruby if itself yields the chosen branch value, and postfix conditionals are also available. Ruby conditions use truthiness rather than requiring bool. Preserve an explicit Dart comparison…
Dart1 2void main() {3const wet=false;final label=wet?"rain":"sun";print(label);4}Ruby1wet = false2icon = if wet3 "umbrella"4else5 "sun"6end7puts iconArrays and Indexing
Dart List may be growable or fixed-length, and invalid indexes throw RangeError. Ruby arrays are growable, ordinary missing reads return nil and negative indexes count from the end. Dart uses last or an explicit valid index for the final element. Use Ruby…
Dart1 2void main() {3final values=[4,8];print(values.last);print(values.length>9?values[9]:"missing");4}Ruby1values = [4, 8]2puts values[-1]3puts(values[9].nil? ? "missing" : values[9])Mutation and Aliases
Dart list assignment shares an object, while List.of creates a separate outer list; Ruby assignment likewise aliases an array. Ruby reverse! mutates and reverse returns another array. Dart final prevents rebinding but allows mutation of a mutable list.…
Dart1 2void main() {3final a=[1]; final b=List<int>.of(a); b[0]=9; print(a[0]);4}Ruby1values = [1, 2, 3]2alias_values = values3values.reverse!4puts alias_values.join(" ")Modules as Namespaces
Dart libraries and imports organize statically resolved declarations, and underscore names are private to their library. Ruby modules organize constants and methods at runtime, with require_relative loading neighboring files. A Ruby filename does not create a…
Dart1String bracket(String text)=>"[$text]";2void main() {3print(bracket("ready"));4}Ruby1module TextTools2 def self.shout(text)3 text.upcase4 end5end6puts TextTools.shout("elm")Composing Objects
Dart and Ruby can retain references to collaborators without cloning them or transferring exclusive ownership. Dart classes supply implicit interfaces and explicit implements contracts, while Ruby commonly uses compatible methods dynamically. Delegation…
Dart1abstract interface class Policy {int apply(int n);}2class DoublePolicy implements Policy {int apply(int n)=>n*2;}3class Order {final Policy policy; Order(this.policy); int total()=>policy.apply(3);}4void main() {5final order=Order(DoublePolicy()); print(order.total());6}Ruby1class 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 questionsStart with Ruby
8 lessonsFlow and Methods
6 lessonsCollections and Blocks
6 lessonsMutation and Errors
5 lessonsObjects and State
5 lessonsComposition and Dispatch
6 lessonsObjects in Practice
6 lessonsLending Desk Project
4 lessonsPort Dart Programs
2 lessonsFrequently asked questions
Who is Ruby for Dart Developers for?
For people who already write Dart and want to learn Ruby. Each lesson starts from Dart 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 Dart basics: variables, conditions, loops, functions and collections.
How many lessons does Ruby for Dart Developers have?
Ruby for Dart Developers contains 48 interactive lessons you can complete at your own pace.
What does Ruby for Dart 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 Dart Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.