In Ruby, you can write multiple variable types based on the following usage.

  • Global Variables
  • Class Variables
  • Instance variables
  • Constant Variables

Global Variables in Ruby

Global variables are declared with $.

These are available across all modules and classes in the same file and the scope is Global.

$company ="""
class Employee{
    def display
        puts "display employee company $company"

class Department{
    def display
        puts "display department company $company"



display employee company
display employee department

Instance variable

The instance variable starts with @ and variable name.

Ruby class variable

a class variable declared with @@