Names and Objects
Lesson 3 of 48 in Coddy's Ruby for Rust Developers course.
Rust bindings have static types, with mut controlling reassignment and shadowing allowing a new binding. Ruby names can be rebound to different kinds of objects. Rust ownership can move a non-Copy value, while Ruby assignment normally shares an object reference. Distinguish rebinding, copying, moving and mutation when translating source assumptions.
Rust: complete program
fn main() {
let x=4; {let x=9; println!("{}",x);} println!("{}",x);
}
Ruby: complete program
label = "cedar"
old = label
label = label.length
puts label
puts oldChallenge
EasyInput is a quantity and a unit price, separated by whitespace. Return their product minus a fixed discount of 3 as decimal text. Both inputs are integers in 0..100.
Return text from solve(input) without printing. The locked driver prints the returned text with one final newline and checks required public APIs independently.
Your code goes in exercise.rb. main.rb holds the supplied input/output code and cannot be edited.
Try it yourself
require_relative 'exercise'
def check(value)
raise 'Public API check failed' unless value
end
puts solve(STDIN.read)
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Ruby for Rust Developers
1Start with Ruby
Run Ruby FilesOutput and CommentsNames and ObjectsInteger ArithmeticTruth and Boolean LogicString OperationsSymbols and KeysRecap: Packing Slip2Flow and Methods
Conditional ValuesCase and RangesLoops and Early ExitMethods and ReturnsDefaults and KeywordsRecap: Sensor Run5Objects and State
Modules as NamespacesClasses and InstancesReaders and WritersValidated ConstructionRecap: Wallet8Lending Desk Project
Lending Desk: CatalogLending Desk: BorrowPractice on your own: Online Ruby compiler