(一)类变量以及类方法
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()
本文介绍了Ruby语言中类变量及类方法的基本概念,并通过一个银行账户类的示例展示了如何定义和使用类变量及类方法。
713

被折叠的 条评论
为什么被折叠?



