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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.