In Ruby, you can write multiple variables types based on 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 a same file and 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

Instance variable starts with @ and variable name.

Ruby class variable

class variable declared with @@