Ruby Basic Syntax

Ruby Basic Syntax

In this tutorial, we will learn the basic syntax of Ruby language. We will go through the key components of a simple Ruby program.

Ruby Program

puts "Hello, World!"
Try with Ruby Compiler ➚


Hello, World!

Basic Syntax of a Ruby Program

  1. puts "Hello, World!"
    This line uses the puts method to output the string "Hello, World!" to the standard output (usually the console).

Key Points to Remember

  • Ruby statements can end with a semicolon (;), but it's often omitted and optional.
  • Ruby is case-sensitive, meaning that puts and PUTS would be considered different.
  • Comments can be added using # for single-line comments or =begin ... =end for multi-line comments.
  • Ruby is known for its concise and readable syntax, as well as its flexibility and object-oriented nature.