注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 GHOST系统封装 全图 教程
 帮助

ruby替我表达失恋的心情


2007-09-19 11:31:51
 标签:ruby   [推送到技术圈]

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://blackanger.blog.51cto.com/140924/43198
 class I
     def self.forget(u,&block)
         @yousomething ="about   "+ u + "   something    "
         if block
            block.call "I forget "+ @yousomething
        else
           @yousomething + "don`t about me"
        end
    end
end
 I.forget('you'){|something| something + "but I still love you"}
=>"I forget about  you  something  but I still love you"


另:



 class You
    def initialize(u)
        @u = u
    end
    def remember
        puts " remember " + @u + " something "
        return self
    end
     def deepen
         p ",I still love" + @u+ " deepen!"
         return self
     end
 end

class I
    def self.forget(u,&block)
         you = You.new(u)
         if block
              block.call you
         else
              you
         end
   end
end

irb(main):087:0> I.forget('you'){|something| something.remember.deepen}

=> remember you something,I still loveyou deepen!





还可以用method_missing方法来造句。。。
待修改


本文出自 “{ :Alex Space => " Ruby Notes " }” 博客,请务必保留此出处http://blackanger.blog.51cto.com/140924/43198





    文章评论
 
2007-09-19 21:02:48
程序员果然不一样啊
再编写个跳出失恋的程序吧

2007-09-20 09:31:12
跳不出来了

2007-11-09 17:26:37
我努力的研究了一下这个我不懂滴领域,不错,发现自己很厉害:有些单词我认识!

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: