(一)类变量以及类方法
sample code

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

相关文章:

  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-05
  • 2022-01-02
  • 2021-12-29
  • 2021-05-16
  • 2021-11-18
  • 2022-12-23
相关资源
相似解决方案