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 本文出自 51CTO.COM技术博客 |



blackanger
博客统计信息
热门文章
最新评论
友情链接

