Menu
CoddyTech

Output and Comments

Lesson 2 of 48 in Coddy's Ruby for Lua Developers course.

Lua uses double-hyphen comments and end to close many constructs. Ruby also uses end, but a hash sign begins its line comments. Lua print separates multiple arguments and adds a newline; io.write does not. Ruby puts and print have their own formatting behavior. Ruby require_relative loads a file relative to the current source file, unlike Lua require module-name resolution.

Lua: complete program

io.write("oak!")
-- A comment
print("#seed")

Ruby: complete program

print "oak!"
# A real comment
puts "#seed"
challenge icon

Challenge

Easy

Return 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)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Ruby for Lua Developers

Practice on your own: Online Ruby compiler