divisible 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -1
- data/Gemfile +1 -1
- data/README.rdoc +16 -6
- data/Rakefile +10 -1
- data/divisible.gemspec +4 -3
- data/lib/divisible.rb +1 -5
- data/lib/divisible/core_ext.rb +12 -4
- data/lib/divisible/version.rb +1 -1
- data/test/test_divisible.rb +50 -0
- metadata +13 -18
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -1,14 +1,24 @@
|
|
1
1
|
= Divisible
|
2
2
|
|
3
|
-
|
3
|
+
Still using the C way of testing if one number is divisible by another?
|
4
|
+
|
5
|
+
Still using this?
|
6
|
+
|
7
|
+
x % 13 == 0 || x % 6 == 0 || x % 3 == 0
|
8
|
+
|
9
|
+
No need anymore! We present you *Divisible*. Check if number is divisible by another like a boss!
|
10
|
+
|
11
|
+
x.divisible_by? 13, 6, 3
|
4
12
|
|
5
13
|
== Examples
|
6
14
|
|
7
|
-
9.divisible_by
|
8
|
-
10.divisible_by
|
9
|
-
12.divisible_by
|
10
|
-
12.divisible_by
|
11
|
-
15.divisible_by
|
15
|
+
9.divisible_by? 3 # => true
|
16
|
+
10.divisible_by? 3 # => false
|
17
|
+
12.divisible_by? 3 # => true
|
18
|
+
12.divisible_by? 4 # => true
|
19
|
+
15.divisible_by? 4 # => false
|
20
|
+
21.divisible_by? 3,7 # => true
|
21
|
+
35.divisible_by? 3,5,0 # => false
|
12
22
|
|
13
23
|
Same can be done with
|
14
24
|
|
data/Rakefile
CHANGED
data/divisible.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
3
|
require 'divisible/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
@@ -14,10 +14,11 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.required_rubygems_version = ">= 1.3.6"
|
16
16
|
s.rubyforge_project = "divisible"
|
17
|
-
|
18
|
-
s.add_development_dependency "
|
17
|
+
|
18
|
+
s.add_development_dependency "rake"
|
19
19
|
|
20
20
|
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
22
|
s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
|
22
23
|
s.require_path = 'lib'
|
23
24
|
end
|
data/lib/divisible.rb
CHANGED
data/lib/divisible/core_ext.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
class Fixnum
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
def divisible_by?(first,*args)
|
3
|
+
args += [first]
|
4
|
+
args.each do |arg|
|
5
|
+
return false unless Divisible.check(self, arg)
|
6
|
+
end
|
7
|
+
true
|
5
8
|
end
|
6
9
|
|
7
|
-
|
10
|
+
# <b>DEPRECATED:</b> Please use <tt>divisible_by?</tt> instead.
|
11
|
+
def divisible_by(*args)
|
12
|
+
warn "[DEPRECATION] `divisible_by` is deprecated. Please use `divisible_by?` instead."
|
13
|
+
divisible_by?(*args)
|
14
|
+
end
|
15
|
+
end
|
data/lib/divisible/version.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "divisible"
|
3
|
+
require "divisible/core_ext"
|
4
|
+
|
5
|
+
|
6
|
+
class TestDivisible < Test::Unit::TestCase
|
7
|
+
def test_if_loaded
|
8
|
+
assert Fixnum.method_defined?(:divisible_by?)
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_module_call
|
12
|
+
assert Divisible.check(4,2)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_simple
|
16
|
+
assert 2.divisible_by?(2)
|
17
|
+
assert !4.divisible_by?(3)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_complex
|
21
|
+
assert 100.divisible_by?(2,4,5,10,20,25,50)
|
22
|
+
assert !100.divisible_by?(2,3)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_complex_with_zero
|
26
|
+
assert_raise ZeroDivisionError do
|
27
|
+
assert_equal false, 100.divisible_by?(2,4,5,10,20,25,50,0)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_blank
|
32
|
+
assert_raise ArgumentError do
|
33
|
+
2.divisible_by?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_division_by_zero
|
38
|
+
assert_raise ZeroDivisionError do
|
39
|
+
assert_equal false, 2.divisible_by?(0)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_that_divisible_by_still_works_as_deprecated_method
|
44
|
+
assert Fixnum.method_defined?(:divisible_by)
|
45
|
+
assert_equal 4.divisible_by(2), 4.divisible_by?(2)
|
46
|
+
assert_equal 4.divisible_by(3), 4.divisible_by?(3)
|
47
|
+
assert_equal 100.divisible_by(2,4,5,10,20,25,50), 100.divisible_by?(2,4,5,10,20,25,50)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
metadata
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
name: divisible
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
hash: 27
|
5
|
-
prerelease:
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Vlado Cingel
|
@@ -15,27 +15,22 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2012-02-27 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
|
-
name: bundler
|
23
21
|
prerelease: false
|
24
|
-
|
22
|
+
name: rake
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
28
|
+
hash: 3
|
30
29
|
segments:
|
31
|
-
- 1
|
32
|
-
- 0
|
33
30
|
- 0
|
34
|
-
|
35
|
-
- 5
|
36
|
-
version: 1.0.0.rc.5
|
31
|
+
version: "0"
|
37
32
|
type: :development
|
38
|
-
|
33
|
+
requirement: *id001
|
39
34
|
description: Useful to find out if one number is divisible by another. For example 9.divisible_by(3) will return true, and 10.divisible_by(3) will return false
|
40
35
|
email:
|
41
36
|
- vlado@cingel.hr
|
@@ -54,7 +49,7 @@ files:
|
|
54
49
|
- lib/divisible.rb
|
55
50
|
- lib/divisible/core_ext.rb
|
56
51
|
- lib/divisible/version.rb
|
57
|
-
|
52
|
+
- test/test_divisible.rb
|
58
53
|
homepage: https://github.com/vlado/divisible
|
59
54
|
licenses: []
|
60
55
|
|
@@ -86,9 +81,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
81
|
requirements: []
|
87
82
|
|
88
83
|
rubyforge_project: divisible
|
89
|
-
rubygems_version: 1.
|
84
|
+
rubygems_version: 1.8.12
|
90
85
|
signing_key:
|
91
86
|
specification_version: 3
|
92
87
|
summary: Useful to find out if one number is divisible by another
|
93
|
-
test_files:
|
94
|
-
|
88
|
+
test_files:
|
89
|
+
- test/test_divisible.rb
|