tutorial ruby - Start using variables and simple objects
Sun Apr 01, 2018 4:12 pm
I take advantage of these first moments of the course with the console to share two small tips that may be useful throughout the course:
to empty the contents of the console, you just have to type Ctrl+ Lon your keyboard (it is a shortcut for the control clear of the console).
to exit the IRB, type exit in your console.
In summary :
To run Ruby code directly in your console, you need to use the Ruby console called IRB (Interactive Ruby) by typing the following command:
irb
Then type the Ruby command that you want.
A variable is a kind of " box" in which content can be stored in different forms: a number, a string (or string ) ... and many other forms that you will discover later in this course !
Operator is used = to store an object in a variable, for example:
cadeau = "bon pour un voyage autour du monde".
It is said that one assigns a value ("good for a journey around the world") to a variable (gift).
Mathematical operations can be performed on variables containing numbers. For example, the age_de_ruby following variable :
age_de_ruby = 2015 - annee_de_naissance_ruby
will contain the value 20 (and yes, Ruby has all the future ahead of him : D).
Variables containing strings can be grouped using the operator + : we say we are concatenating . For example, the message following variable :
message = "Bravo, tu as reçu un " + cadeau + " !"
will contain the value "Bravo, tu as reçu un bon pour un voyage autour du monde !"
to empty the contents of the console, you just have to type Ctrl+ Lon your keyboard (it is a shortcut for the control clear of the console).
to exit the IRB, type exit in your console.
In summary :
To run Ruby code directly in your console, you need to use the Ruby console called IRB (Interactive Ruby) by typing the following command:
irb
Then type the Ruby command that you want.
A variable is a kind of " box" in which content can be stored in different forms: a number, a string (or string ) ... and many other forms that you will discover later in this course !
Operator is used = to store an object in a variable, for example:
cadeau = "bon pour un voyage autour du monde".
It is said that one assigns a value ("good for a journey around the world") to a variable (gift).
Mathematical operations can be performed on variables containing numbers. For example, the age_de_ruby following variable :
age_de_ruby = 2015 - annee_de_naissance_ruby
will contain the value 20 (and yes, Ruby has all the future ahead of him : D).
Variables containing strings can be grouped using the operator + : we say we are concatenating . For example, the message following variable :
message = "Bravo, tu as reçu un " + cadeau + " !"
will contain the value "Bravo, tu as reçu un bon pour un voyage autour du monde !"
Permissions in this forum:
You cannot reply to topics in this forum