Ruby on Rails

Ruby Variables, constants, datatypes and keywords

ruby constants variables datatypes keywords
Written by deathdealer

Ruby Variables

Hi there !

In this tutorial we are gonna be learning about the constants, variables, datatypes and keywords in Ruby. So first we are gonna begin with the constants.

Constants:

As the name indicates a constant is an entity which doesn’t change. We have different types of constants.

Integer Constants:

We have integer constants which is an whole number, for example 44 or we have 86 or any whole number which is an integer constant.

Float Constants:

We have floating point constants, for example 12.23, you know a number with decimal values, 34.53 etc etc. So all these are floating point constants.

String Constants:

We have string constants which are written in double quotes for example “google” and we have any other string for example “Ruby on Rails” which is written in double quotes and which is a bunch of characters. These are called string constants.

Variables:

A variable is nothing its just a name given to a memory location in order to access it easily. So when we give a name or create a variable in our program, whenever we refer to that variable, for example

yamaha = 2019;

Here yamaha is a variable and 2019 is the value being assigned to that variable yamaha.

Data Types:

The type of data stored in a variable is called data type. We have integer data types which refers to the integer constants, we have floating point, we have boolean.

So a data type is nothing but what type of data is stored in a variable or a memory location. So we have integer, floating point, boolean which is true or false.

Keywords:

These keywords are nothing but the words whose meanings are already defined to our compiler. There are many keywords available in Ruby. For example we have class whose meaning is already defined to the compiler, we have def, we have to_f, and many are there. So the main thing is we can’t use these keywords as our variable name.

So this is it guys, this is about some information on constants, variables, data types and keywords. Thanks for reading !

Check out c++ constants, variables, keywords and datatypes.

About the author

deathdealer

Leave a Comment