class Person
def name # 通过该方法,可以获得实变量@name的值
return @name
end
def name=(name) # 通过name= 方法可以改变@name的值
@name = name
end
end
axs = Person.new # 新建Person类的实例axs
axs.name = "FlameHaze" # 通过 name= 方法改变@name的值
p axs.name #通过name方法取得并输出对象axs中实变量@name的值
attr_reader :name
def name
return @name
end
axs = Person.new # 新建Person类的实例axs
axs.name = "FlameHaze"
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |