本博客不再更新

          本博客不再更新,請(qǐng)?jiān)L問http://blog.sina.com.cn/fulaoshi

          統(tǒng)計(jì)

          最新評(píng)論

          [導(dǎo)入]Ruby版的父親打孩子

          以前在講多態(tài)的時(shí)候總喜歡舉父親打孩子的例子,今天寫了一個(gè)Ruby版,稍后獻(xiàn)上Ruby語(yǔ)法速查

          class Father
          ? attr_accessor :name
          ?
          ? def initialize(name)
          ??? @name = name
          ? end
          ?
          ? def beat(child)
          ???
          ??? child.beaten
          ???
          ? end
          ?
          end

          class Son < Father

          ? def beaten
          ??? puts @name + " is running away while father beat him";
          ? end
          ?
          end

          class Daughter < Father

          ? def beaten
          ??? puts @name + " is crying while father beat her";
          ? end
          ?
          end

          father = Father.new('Father')
          son = Son.new('Son')
          daughter = Daughter.new('Daughter')

          father.beat(son)
          father.beat(daughter)


          文章來源:http://blog.sina.com.cn/u/4a5ca02401000761

          posted on 2007-03-21 23:30 本博客不再更新 閱讀(105) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 德昌县| 衡水市| 铜梁县| 宜川县| 登封市| 牟定县| 佛教| 辽阳县| 邓州市| 沂源县| 南城县| 泰州市| 盘山县| 太谷县| 邢台市| 叶城县| 大埔县| 奉节县| 阿城市| 东平县| 环江| 米易县| 光泽县| 托里县| 会泽县| 兰考县| 宜良县| 广昌县| 台南县| 菏泽市| 卓尼县| 南皮县| 万年县| 阳春市| 沈阳市| 龙游县| 怀宁县| 龙口市| 安吉县| 鄂托克旗| 博野县|