In this section we will learn what data types are and how to use them in Ruby
What is Data Type in Ruby?
Every thin in Ruby is of some type! For example a number like 33.3 is of Float type. Or a series of characters followed by each other and surrounded in a pair of double quotation is called String. Or a value like true or false is called Boolean value.
This is what data type is all about. We use data types to differentiate between the values exists in a program and based on their type, each will have different set of behavior!
For example, if the type of a value is string for example, there are methods that allow you to uppercase the characters of that string value. Or if the type is float for example you’ll be able to involve the value into mathematical operations like multiplication, division, subtractions etc.
So in short, values in Ruby have data types and based on their types you can expect different set of behaviors from them.
List of Data Types in Ruby
The category of data types in Ruby is as follow:
– Numbers
– Boolean
– String
– Compound Data Types
Some of these data types have sub-categories which you’ll soon see those as well.
Ruby Numbers
-Fixnum
-Float
Ruby Fixnum Data Type
Example: using fixnum values in Ruby
Ruby Float Data Type
Example: using float values in Ruby
Ruby Boolean Data Type
(explain the values true and false, why they are used and also mentioned that there are operators that produce boolean values etc.)
Example: using boolean values in Ruby
Ruby String Data Type
Example: using string values in Ruby
Ruby Compound Data Type
– Arrays
– Hashes
Ruby Arrays Data Type
Example: using Arrays in Ruby
Ruby Hashes Data Type
Example: using Hashes in Ruby
Ruby Symbols
Example: using Symbols in Ruby
Ruby Objects
(explain the entire data types mentioned so far are objects and a little about objects themselves…)
(Then link to the related article)