AnyCompiler

Your First Ruby Program

A Ruby file has no compile step and no required entry-point function — no main, no class wrapper, nothing. The interpreter runs top-level statements in order, the moment the file executes. puts writes a value followed by a newline. print writes a value with no trailing newline added for you, so you write \n explicitly wherever you want one. Comments start with # and run to the end of the line.

Run it yourself

This was actually executed to get the output shown below — try changing the text and running it yourself using the button under the example.

# This is a comment
puts "Hello, Ruby!"
print "No newline here"
print " - still same line\n"
Output
Hello, Ruby!
No newline here - still same line

Notice the two print calls landed on the same output line — print never adds a newline on its own, unlike puts. Next: variables and types — no declaration keyword at all, and what dynamic typing actually looks like.

Practice exercise

Add a comment above your code, then print "Learning Ruby one step at a time."