Basic Operations
The basic operations of one programming language is the basic math and logical operators.
Math
- Sum
- Minus / Division
- Multiplication
To use this operators we can open our IRB and test it!
All you need to do is use the operator with numbers that we want, the same as math notation.
# Sum
5 + 5
# => 10
# Minus
5 - 3
# => 2
# Multiplication
5 * 2
# => 10
# Division
10 / 2
# => 5
Also in almost all programming langues we have the modulo operator %
that return the remainder of the division, for example the division of 10/3
will result on 3 but 3x3 it's not 10, and we know it! If you want to know the remainder of this count you need to use 10%3
and the result will be 1!
10/3
# => 9
10%3
# => 1
Try yourself to use the previus knowledges to train by yourself, and if you have any question, please ask!
What is variable?
What is the primary kinds of variable?
String Words Number Numbers Boolean True / False
In other languages (usually compiled languages) we also have much more primary var types like bool
, float
, int
, bigint
, char
etc. The magic behind ruby and other interpreted languages is that Ruby do it for you, and you dont't have to explict the var type, the Ruby do all for you, you just need this three types String
, Number
and Boolean
.
To declare a new variable all that you need to do it's to type a name that you want to call your variable and the value, to assign a value to variable is just use the operator =
, for example:
To assign to a variable named ten
the value 10 you just need to do this:
ten = 10
Now every time you need to call this variable is just write "ten" and will return the value stored, in this case 10. Let's see the result if we use puts
passing our variable:
puts ten
# => 10
Yes, you print the value of variable, let's see now the same thing but with words.
name = "Martin Luther King"
puts name
# => Martin Luther King