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 | a96fbe6ac48093a9c3bef44e3c7f0dd5c6782f90 (patch) | |
tree | 72ebdc64f587f563b2b8611db662805fd67dfcbb /lib | |
parent | 1cca2e29eecd72652be3ac09aedc581f5e31456d (diff) | |
download | ruby-a96fbe6ac48093a9c3bef44e3c7f0dd5c6782f90.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')
-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 |