類的定義:
class 類名
??? def 方法名
??? ?? ...
??? end
end
類的實例化(申明對象):
對象名 = 類.new
繼承:
class 子類名<超類名
??? def 方法名
??? ?? ...
??? end
end
super:調用超類方法。也可以向原有的方法傳遞參數。
單態方法:特定對象的特定方法
ruby>?class?SingletonTest
????|???def?size
????|?????print?"25\n"
????|???end
????|?end
???nil
ruby>?test1?=?SingletonTest.new
???#<SingletonTest:0xbc468>
ruby>?test2?=?SingletonTest.new
???#<SingletonTest:0xbae20>
ruby>?def?test2.size
????|???print?"10\n"
????|?end
???nil
ruby>?test1.size
25
???nil
ruby>?test2.size
10
???nil