HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to RubyVariablesData TypesOperatorsStringsArraysHash (Dictionary)Conditions (if / else)LoopsMethods (def)Classes
REFERENCE
📖 Overview
🖥️ Output & Input
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Array
🗂️ Hash (Dictionary)
🔁 Condition & Loop
🧩 Method & Class
Ruby›Introduction to Ruby

Introduction to Ruby

First step into Ruby, the happy developer language: printing with puts, variables, and string interpolation.

Simple enough for a 5-year-old to understand

Print with puts

puts is used to print to the screen in Ruby. Very simple: not even a semicolon is needed.

Your first program
1
puts "Hello!"
Writes text and moves to a new line.
Output / InputWrites text and moves to a new line.
Output / Input
💡 Hint: puts moves to a new line after each print; print does not.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (2 left)

1.Which one is most commonly used to print to the screen in Ruby?
2.Print exactly Hello World to the screen.

🎯 Expected output: Hello World

Loading editor…

About this topic

Ruby was developed by Yukihiro Matsumoto in 1995, and its design goal was unusually human-centric: to make the programmer happy. This is visible everywhere in the language — readability comes before machine efficiency.

In Ruby, everything is an object. Numbers, texts, and even nil are objects and methods can be called on them. This consistency reduces the number of special cases in the language; once you learn a rule, it applies everywhere.

Ruby's popularity came with the Rails framework. For web application development, Rails was the de facto standard for a period and remains a strong choice today. Ruby is also widely used in scripting, automation, and tool development.

What you will learn

  • printing to the screen with puts
  • that semicolons and parentheses are optional in Ruby
  • writing comments
  • running the file
  • the difference between print and puts

Who is this for?

  • Those who want to start web development with Rails
  • Those looking for a language that prioritizes readability
  • Those who will do automation and scripting

When to use?

Ruby is used in web backends, configuration and deployment scripts, data transformation tasks, and developer tools.

Ruby is slow for compute-intensive tasks; compiled languages are preferred in that area. Ruby's strength is its development speed.

Common mistakes

Wrong

Puts "Hello"

Ruby is case-sensitive, and names starting with a capital letter are considered constants. The interpreter gives an "uninitialized constant Puts" error. Method names in Ruby always start with a lowercase letter.

Correct

puts "Hello"

Wrong

name = "Ali"
puts "Hello name"

The variable does not embed into the text automatically; it literally prints "Merhaba name" to the screen. There is no error message, just incorrect output. To embed values, the hash and curly braces syntax is used, and this only works in DOUBLE quotes.

Correct

name = "Ali"
puts "Hello #{name}"

Wrong

puts 'Total: #{2 + 3}'

Interpolation does not work in single-quoted text; the expression itself is printed literally to the screen. Single quotes take the content as-is, while double quotes process interpolation and escape sequences. This distinction is often confused in Ruby.

Correct

puts "Total: #{2 + 3}"

Frequently asked questions

What is the difference between puts and print?

puts adds a newline at the end, print does not. Also, when puts receives an array, it prints each element on a separate line. If you want to see the value for debugging purposes, the p method is more appropriate: it shows texts with quotes and makes nil visible.

Are semicolons and parentheses required?

None of them are mandatory. A newline ends the statement, and parentheses are optional in method calls. The community convention is: write parentheses in method DEFINITIONS, and omit them in simple calls. Parentheses must be used where ambiguity arises.

Is Ruby slow?

Compared to compiled languages, yes, and this is a conscious trade-off: Ruby prioritizes developer productivity. In most web applications, the bottleneck is the database, not the language. When compute-intensive parts are needed, delegating to a C extension or another service is the usual solution.

Summary

In Ruby, everything is an object and method names start with lowercase letters.

Embedding values inside text only works in double quotes.

Semicolons and parentheses are optional.

puts adds a newline, print does not.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code