Tag: method chaining

Ruby挑战 – 方法链和懒惰评估

阅读文章http://jeffkreeftmeijer.com/2011/method-chaining-and-lazy-evaluation-in-ruby/后 ,我开始寻找方法链和懒惰评估的更好解决方案。 我想我已经用下面的五个规范封装了核心问题; 谁能让他们全部通过? 一切顺利:子类化,委托,元编程,但后者不鼓励。 将依赖关系保持在最低限度是有利的: require ‘rspec’ class Foo # Epic code here end describe Foo do it ‘should return an array corresponding to the reverse of the method chain’ do # Why the reverse? So that we’re forced to evaluate something Foo.bar.baz.should == [‘baz’, ‘bar’] Foo.baz.bar.should == [‘bar’, ‘baz’] end it ‘should be […]