{}const=>[]async()letfn</>var
BasicsDevelopmentOverview

Ruby is a language that makes programming fun! 💎

Ruby is a powerful and convenient programming language that makes the code clean and understandable. In this article, you will learn how to install Ruby, work with variables, loops, conditions, and even write your first programs! Everything is simple and accessible even for beginners. 🚀

К

Kodik

Author

3 min read

What is Ruby? 💎

Ruby is a programming language that appeared in 1995 and quickly became a favorite of developers due to its simplicity and beauty. Its motto is "A programmer should enjoy the code." If you like clean and understandable code, Ruby is a great choice! 🚀

This language is actively used for web development, task automation, game creation, and even writing bots. The most famous web technology on Ruby is Ruby on Rails framework, which allows you to quickly create powerful websites and web applications. 🌍

How to start programming in Ruby? 💻

To work with Ruby, you will need:

How to check if Ruby is installed? 🛠

Open the terminal and enter:

ruby -v

If Ruby is installed, you will see its version, for example:

ruby 3.1.2
🔥 100,000+ students already with us

Tired of reading theory?
Time to code!

Kodik — an app where you learn to code through practice. AI mentor, interactive lessons, real projects.

🤖 AI 24/7
🎓 Certificates
💰 Free
🚀 Start learning
Joined today

Ruby's main features 🔧

  • Simplicity: Ruby has a clear syntax, similar to plain English.

  • Flexibility: You can easily change the code and add new features.

  • Object-orientedness: Everything in Ruby is an object!

  • High performance: Ruby is great for automation and working with text.

Ruby Syntax Basics 📚

1. Variables 📦

In Ruby, you don't need to specify the type of a variable — the language itself determines that it is a number, string, or other object.

Example of a numeric variable:

age = 25

Example of a string variable:

name = "Alice"

2. Data input and output 📤📥

In Ruby, you can easily display text on the screen using puts, and receive data from the user through gets.

Example of display:

puts "Hello, world!"

Example of data entry:

print "Enter your name: "
name = gets.chomp
puts "Hi #{name}!"

3. Conditional operators (if...else) 🧐

Using conditions, you can check data and change the behavior of the program.

Example:

if age >= 18
  puts "You're an adult!"
else
  puts "You're still a child."
end

4. Loops (while, times, each) 🔄

Ruby supports several types of loops. For example, the times loop performs an action several times.

Example: output of numbers from 1 to 5

5.times do |i|
  puts i + 1
end

5. Functions (methods) 📐

The methods allow you to structure the code and reuse it.

Example of a function for calculating the square of a number:

def square(x)
  x * x
end

It is called like this:

result = square(5)
puts result

Simple projects in Ruby 💡

1. Addition calculator ➗

The program adds two numbers and displays the result.

num1 = 10
num2 = 5
result = num1 + num2
puts "Addition result: #{result}"

2. Random number generator 🎲

Each time you start, a new number will appear.

puts rand(1..100)

3. "Guess the number" game 🎯

The computer thinks of a number, and the player tries to guess it.

secret = rand(1..10)
guess = nil

puts "I thought of a number from 1 to 10. Try to guess!"

until guess == secret
  print "Your option: "
  guess = gets.to_i
  puts "Not enough!" if guess < secret
  puts "A lot!" if guess > secret
end

puts "Congratulations, you guessed it!"

Conclusion 🎉

Ruby is a powerful but easy-to-learn programming language. We have covered the basics: variables, input/output, conditions, loops, and functions. Now you can write your first programs in Ruby! 🚀

Remember: programming is a skill that develops with practice. The more you code, the better! Good luck learning Ruby! 😊

🎯Stop procrastinating

Liked the article?
Time to practice!

In Kodik, you don't just read — you write code immediately. Theory + practice = real skills.

Instant practice
🧠AI explains code
🏆Certificate

No registration • No card