1
我想通過一個rspec,通常我會做一個方法,並通過一個函數。 我只需要添加一個,我很尷尬我甚至在這裏發佈.. 。總和使用塊
通常我會做
def adder(n)
n+1
end
不過,我需要在一個塊中傳遞和我不熟悉它。
describe "adder" do
it "adds one to the value returned by the default block" do
adder do
5
end.should == 6
end
it "adds 3 to the value returned by the default block" do
adder(3) do
5
end.should == 8
end
end
我試圖
def adder
yield {|n| return n+1 }
end
你的問題不明確。另外,什麼是「加法器」? – sawa
@sawa OP正在嘗試使用塊來完成... –
函數rspec的名稱正在尋找 – user3597795