Assign this or that in Ruby

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

In Ruby, the keywords this and that are not used to refer to specific objects or variables. However, you can assign values to variables using the assignment operator =.

For example, if you want to assign the value 5 to a variable named num, you can write:

num = 5

If you want to assign a string value to a variable named name, you can write:

name = "John Doe"

You can also assign the value of one variable to another variable using the assignment operator:

x = 10
y = x

In this case, the value of the variable x (which is 10) is assigned to the variable y.

You can also assign the result of an expression or method to a variable. For example, if you want to assign the result of adding two numbers x and y to a variable called sum, you can write:

x = 15
y = 20
sum = x + y

In this case, the sum variable will be assigned the value of 35.