Creating a Basic Script

A Ruby script is a plain text file that can be created in most text editors or Integrated Development Environments (IDEs). As for the script’s basic syntax, there is none! Ruby does not require opening and closing tags like PHP or a main function like Java, C, or C++.

Most programming books use the common Hello, world! example to demonstrate a basic script. Rather than rehash something you’ll find everywhere, this first script will be a novel and impressive Greetings, planet! example instead: When the script is executed, it will output that message.

One way to generate output in Ruby is to use the aptly named print method:

print “Whatever text”

Do note that unlike other programming languages you may have seen or used, ...

Get Ruby: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.