Ruby provides four types of variables
Local variable: Lowercase letter or _ Start
Instance variable: an instance variable can span a method of any particular instance or object, meaning that an instance variable from an object to an object is changed. The instance variable is preceded by the at sign @, followed by the variable name
Class variables: Class variables are available in a variety of different objects a class variable belongs to a class is a feature of the class they precede the symbol @@ followed by the class variable name
Global variables: Class variables cannot span classes if you want a single variable that can cross a class need to define a global variable before the global variable is always preceded by a dollar sign $
=end
=begin
Using the new method in Ruby to create an object object is an instance of a class
=end
Class Customer
@ @no_of_customers = 0 #使用类变量 @@ To determine the number of objects created
@no_of_wheels
def initialize #重写初始化方法
@no_of_wheels = "324243234"
End
DEF initialize (wheels) #自定义初始化方法 Incoming parameters Wheels
@no_of_wheels = Wheels
End
def hello
Puts "hello#{@ @no_of_customers}#{@no_of_wheels}"
End
End
#调用对象方法
Object = Customer.new ("Werrwerwrew")
Object.hello
Ruby Classes and methods