Ruby Data Types

[Solved] Ruby Data Types | Ruby - Code Explorer | yomemimo.com
Question : variable types in ruby

Answered by : fabrizio-r4efh8bzkyid

There are four types of variables in Ruby:
1. Local variables: starts with a lowercase letter or underscore _). It is only accessible or have its scope within the block of its initialization. Once the code block completes, variable has no scope.
2. Class variables: starts with @@ sign. They need to be initialized before use. A class variable belongs to the whole class and can be accessible from anywhere inside the class.
3. Instance variable: starts with a @ sign. It belongs to one instance of the class and can be accessed from any instance of the class within a method. It has limited access to a particular instance of a class. Doesn't need to be initialized.
4. Global variables: starts with a $ sign. Its scope is globally, means it can be accessed from anywhere in the program.

Source : https://www.javatpoint.com/ruby-variables | Last Update : Thu, 27 Oct 22

Answers related to ruby data types

Code Explorer Popular Question For Ruby