ruby oop学习
class Man def initialize(name,age) @name=name @age=age end def sayName puts @name end def sayAge puts @age end end m=Man.new('tianen',213) m.sayAge m.sayName class Man def initialize(name,age) @name=name @age=age end def sayName puts @name end def sayAge puts @age end end class T < Man def sayName super puts "i love you" end def love puts "this is love" end end t=T.new("toi",12) t.sayName t.love class Man def initialize(name,age) @name=name @age=age end def sayName puts @name end def sayAge puts @age end end a=Man.new('a',5) b=Man.new('b',6) def b.sayName puts "this is b" end b.sayName def my puts 'my Lover' end my s='good' s.my class Man def initialize(name,age) @name=name @age=age end private def sayNam puts @name end def sayAge puts @age end public def free puts "I am a public method" end end t=Man.new('wangwenfei',23) # t.sayName # t.sayAge t.free
posted on 2013-07-02 23:02 Ijavascript 阅读(185) 评论(0) 编辑 收藏 举报