(一)类变量以及类方法
sample code
class BankAccount
@@interestRate = 6.5
def BankAccount.getInterestRate()
@@interestRate
end
attr_accessor :balance
def initialize(bal)
@balance = bal
end
end
puts BankAccount.getInterestRate()
以上代码中描述了如何定义类变量以及如何访问类变量
@@interestRate = 6.5
def BankAccount.getInterestRate()
@@interestRate
end
attr_accessor :balance
def initialize(bal)
@balance = bal
end
end
puts BankAccount.getInterestRate()