Ruby之旅(三) 类变量以及类方法

来源:互联网 发布:澳洲留学费用 知乎 编辑:程序博客网 时间:2024/05/20 18:45
Ruby之旅(三) 类变量以及类方法

(一)类变量以及类方法
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()
以上代码中描述了如何定义类变量以及如何访问类变量
0 0