diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-20 03:19:44 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-20 03:19:44 +0000 |
commit | 487736646a8c50718289d4c1d71e4c63ad641b43 (patch) | |
tree | 72ebdc64f587f563b2b8611db662805fd67dfcbb /lib/prime.rb | |
parent | 8744d5164d4434d73ded703063363a3c90b337b7 (diff) | |
download | ruby-487736646a8c50718289d4c1d71e4c63ad641b43.tar.gz |
* lib/prime.rb: Add basic argument checking to Prime.prime?
[Bug #11606]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/prime.rb')
-rw-r--r-- | lib/prime.rb | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/prime.rb b/lib/prime.rb index d99a51a967..c79b0cfd5f 100644 --- a/lib/prime.rb +++ b/lib/prime.rb @@ -144,6 +144,8 @@ class Prime # +value+:: an arbitrary integer to be checked. # +generator+:: optional. A pseudo-prime generator. def prime?(value, generator = Prime::Generator23.new) + raise ArgumentError, "Expected a prime generator, got #{generator}" unless generator.respond_to? :each + raise ArgumentError, "Expected an integer, got #{value}" unless value.respond_to?(:integer?) && value.integer? return false if value < 2 generator.each do |num| q,r = value.divmod num |