Primitives in Ruby

Find this useful? Support us: Star on GitHub 6
Category: Datatypes | Language: Ruby

Sure, as an AI language model, I can help you with that.

In Ruby, there are several primitive data types. Here are some examples:

1. Integers: These represent whole numbers and can be positive, negative, or zero.

Example: 50, -10, 0

2. Floats: These represent decimal numbers.

Example: 3.14, -0.5, 9.0

3. Booleans: These represent true/false values.

Example: true, false

4. Strings: These represent text. They can be surrounded by single quotes (') or double quotes (").

Example: "hello", 'ruby', "123"

5. Symbols: These represent immutable values that are commonly used as keys in hashes.

Example: :name, :age, :address

Here is an example of a Ruby code that uses some of these primitive data types:

age = 25         # integer
height = 5.11    # float
is_male = true   # boolean
name = "John"    # string
city = :Austin   # symbol

I hope that helps!