我有这个测试在Ruby中,我试图实现 要求“silly_blocks”实现问题
describe "some silly block functions" do
describe "reverser" do
it "reverses the string returned by the default block" do
result = reverser do
"hello"
end
result.should == "olleh"
end
it "reverses each word in the string returned by the default block" do
result = reverser do
"hello dolly"
end
result.should == "olleh yllod"
end
end
的方法
def do_reverse(str)
str = str.split
first_str = str[0].reverse
second_str= str[1]
if (second_str == nil)
str = first_str.to_s
else
second_str = str[1].reverse
str = (first_str +" "+ second_str)
end
end
什么是最好的方法我可以实现它。当我试图耙测试它失败,但方法本身返回储备。我只是有点困惑。
是的,它很重要。我分享的规范不是由我完成的,他们给我实施方法 – 2013-02-17 19:23:16
更新的答案,包括'reverser',它适用于块 – cfeduke 2013-02-17 19:38:01