Output and Comments
Lesson 2 of 48 in Coddy's Ruby for Java Developers course.
Java starts execution in a main method and uses braces to delimit bodies. Ruby executes top-level statements in the entry file and closes many constructs with end. Ruby require_relative loads neighboring source files at runtime; Java resolves compiled classes through its classpath. Java println and Ruby puts add a line ending, whereas print can omit one.
Java: complete program
import java.util.*;
public class Main {
public static void main(String[] args) {
System.out.print("oak!");
// A comment
System.out.println("#seed");
}
}Ruby: complete program
print "oak!"
# A real comment
puts "#seed"Challenge
EasyReturn two lines: the word Ticket and then the stripped input. Do not print inside the helper.
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
STDOUT.write(solve(STDIN.read) + 10.chr)
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Ruby for Java 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