SoFunction
Updated on 2025-03-10

The difference between Ruby class instance variables, class instance methods, class variables, and class methods


class A 
#Class variables must be assigned before accessing, otherwise there will be an "uninitialized class variable" error
  @@alpha=123                # Initialize @@alpha 
  @@beta=456                 #Initialize @@beta 
  @@gamma=789              #Initialize @@gamma 
  
  def  
    @@alpha 
  end  
  
  def =(x) 
    @@alpha=x 
  end 
  
  def  
    @@beta 
  end 
  
  def =(x) 
     @@beta=x 
  end  
   
  def  
   @@gamma 
  end 
  
  def =(x) 
    @@gamma=x 
  end  
  def  
    puts "#@@alpha, #@@beta, #@@gamma" 
  end 
  end 
 
 
class B<A   
end 
 
#Initial data
 
 
 
#Modify class variables in parent class
=111