Zoonk icon

Ruby (programming language)

Ruby is an interpreted, high-level, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.

Ruby is dynamically typed and uses garbage collection. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming.

Write an article
Numbers in Ruby

There are a few types of numbers available in Ruby. Let's see some examples: fruits = 10 lottery_prize = 42000000 price = 4.20 expression = 1 + 2i fraction = Rational(1, 3) precise_price = BigDecimal(

Data types in Ruby

When we're creating a variable in Ruby, we're also assigning a data type to it. For example, when we write something like this: car = "Tesla" We're actually telling our program to create a varia

How to declare variables in Ruby

Variables are values you can declare to use later. For example, let's say we want to save someone's name in our program. We can do it by declaring a new variable: name = "Nikola Tesla" In the exa

Hashes in Ruby

If you're coming from other programming languages, you might know hashes as a "dictionary" or an "object". Like arrays, can also store multiple items. But, different from arrays, you can access them

Arrays in Ruby

We've already learned about many data types such as strings, numbers, booleans, and symbols. Using , we can store many of those items in the same variable: cool_websites = ["zoonk", "khan academy"

Symbols in Ruby

Symbols are similar to strings but they are identifiers rather than data. They're different than strings, though, as you cannot change them. For example, if you call 10 times, it will actually crea

Strings in Ruby

Strings are text representations. You can use them to name things. For example: app_name = "Zoonk" scientist = "Albert Einstein" You can also join two different strings by using the sign: firs

Booleans and Nil in Ruby

In programming, a is like a toggle value which can be either or . For example, let's say you want to check a menu status (whether it's open or closed). You could create a boolean variable for that:

How to create classes in Ruby?

Classes are commonly used in Object-Oriented Programming (OOP). They help you define a basic model for creating objects. For example, let's create a class to handle data about movies: class Movie

How to run a script from a Ruby file

When you're developing software using Ruby, you'll probably need to write a Ruby file to run your scripts rather than using the . First, let's create a file (remember: Ruby files end with the exte