Skip to content

Instantly share code, notes, and snippets.

@chikoski
Created April 19, 2013 02:13
Show Gist options
  • Save chikoski/5417633 to your computer and use it in GitHub Desktop.
Save chikoski/5417633 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'rspec'
module Factorial
def without_keyword(n)
return 1 if n < 2
return without_keyword(n-1) * n
end
def with_keyword(n: 10)
return without_keyword(n)
end
module_function :without_keyword, :with_keyword
end
describe Factorial, "#with_keyword" do
it "キーワードで引数を与えられる" do
(Factorial.with_keyword n:5).should eq 120
end
it "引数を与えない場合はデフォルトの物が使用される" do
(Factorial.with_keyword).should eq 3628800
end
it "キーワードを指定しないで引数を与えるとArgumentErrorが起きる" do
proc{
Factorial.with_keyword 5
}.should raise_error ArgumentError
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment