不明な数の引数 (したがって *splat) を取るが、yields_with_args
仕様を渡すメソッドを作成する必要があります。
コード:
def eval_block(*args, &block)
raise "NO BLOCK GIVEN!" if block.nil?
block.call(args)
end
rspec:
it "passes the arguments into the block" do
expect do |block|
eval_block(1, 2, 3, &block)
end.to yield_with_args(1, 2, 3)
end
end
それは機能しますが、 *splat が作成する配列[1,2,3]
vsを生成する1,2,3
ため、rspec を渡しません。Rubyのメソッドを介して複数の引数を渡す別の方法はありますか?