本博客不再更新

          本博客不再更新,請訪問http://blog.sina.com.cn/fulaoshi

          統計

          最新評論

          [導入]Ruby版的父親打孩子

          以前在講多態的時候總喜歡舉父親打孩子的例子,今天寫了一個Ruby版,稍后獻上Ruby語法速查

          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) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 丰台区| 綦江县| 开远市| 云霄县| 正镶白旗| 广平县| 瓮安县| 拜泉县| 漯河市| 商南县| 正宁县| 瓦房店市| 仙游县| 文登市| 井冈山市| 泗阳县| 林口县| 虹口区| 古交市| 永宁县| 类乌齐县| 山丹县| 普格县| 禹州市| 五常市| 延川县| 安陆市| 山丹县| 金坛市| 竹溪县| 多伦县| 大悟县| 左贡县| 丹阳市| 新蔡县| 田阳县| 桂平市| 筠连县| 南川市| 宝丰县| 城口县|