闲云无衣
无衣的笔记
类的定义:
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
posted on 2007-02-07 14:31 无衣 阅读(188) 评论(0)  编辑  收藏 所属分类: rails