idivisor 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +6 -0
- data/{divisor.gemspec → idivisor.gemspec} +0 -0
- data/lib/idivisor.rb +18 -5
- data/lib/idivisor/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 949393ce9a778d6c778a1055f7692ae9a8d0cd9f97c1d78368d010eeaa1a66e9
|
4
|
+
data.tar.gz: 8b105e8923180791a2988d0bbbc040d70a9b49919e8533225b3c9841b972f388
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af2d5e7c18b899a362138f0c0efb1488dd21f153295c21d90720f0f0e98ef531169c9ba8fcc37b76459eef736a61032a0183d6353d56d721b8edf17cd6e88596
|
7
|
+
data.tar.gz: 7b13ef2a7596f57832972f8b6758c57b6a8f8b0f1a652bd82f5118432427dd7ed228684bc2d9d78062ea57d1b4e3cc79a0d0888845dd8cc56040ff787d6c5470
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -30,6 +30,8 @@ p 100.each_diviror.to_a #=> [1, 2, 4, 5, 10, 20, 25, 50, 100]
|
|
30
30
|
p 4.has_divisor?(2) #=> true
|
31
31
|
p 4.divisible_by?(3) #=> false
|
32
32
|
|
33
|
+
# 3 is a divisor of 9.
|
34
|
+
# 4 is not a divisor of 2
|
33
35
|
p 3.divisor_of?(9) #=> true
|
34
36
|
p 4.divisor_of?(2) #=> false
|
35
37
|
```
|
@@ -40,6 +42,10 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
40
42
|
|
41
43
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
44
|
|
45
|
+
### test
|
46
|
+
|
47
|
+
`$ rake test`(`$ rake`) or `$ ruby test/idivisor_test.rb`
|
48
|
+
|
43
49
|
## Contributing
|
44
50
|
|
45
51
|
Bug reports and pull requests are welcome on GitHub at https://github.com/universato/idivisor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/universato/idivisor/blob/master/CODE_OF_CONDUCT.md).
|
File without changes
|
data/lib/idivisor.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
require "idivisor/version"
|
2
2
|
|
3
3
|
class Integer
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
# Returns +true+ if other integer is a divisor of self integer.
|
6
|
+
# 15.divisible_by?(5) #=> true
|
7
|
+
# 15.divisible_by?(4) #=> false
|
8
|
+
def divisible_by?(other)
|
9
|
+
self % other == 0
|
6
10
|
end
|
7
11
|
alias has_divisor? divisible_by?
|
8
12
|
|
9
|
-
|
10
|
-
|
13
|
+
# Returns +true+ if self integer is a divisor of other integer.
|
14
|
+
# 5.divisor_of?(15) #=> true
|
15
|
+
# 4.divisor_of?(15) #=> false
|
16
|
+
def divisor_of?(other)
|
17
|
+
other % self == 0
|
11
18
|
end
|
12
19
|
|
13
|
-
#
|
20
|
+
# Returns an array of the divisors of the integer.
|
21
|
+
# 15.divisors #=> [1, 3, 5, 15]
|
22
|
+
# 16.divisors #=> [1, 2, 4, 8, 16]
|
14
23
|
def divisors
|
15
24
|
n = self # .abs
|
16
25
|
s = Integer.sqrt(n)
|
@@ -26,6 +35,10 @@ class Integer
|
|
26
35
|
res1.concat(res2)
|
27
36
|
end
|
28
37
|
|
38
|
+
# list positive divisors from positive integer.
|
39
|
+
# 4.each_divisor do |i|
|
40
|
+
# puts i
|
41
|
+
# end
|
29
42
|
def each_divisor
|
30
43
|
return enum_for(:each_divisor) unless block_given?
|
31
44
|
|
data/lib/idivisor/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idivisor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- universato
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02
|
11
|
+
date: 2021-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: divisors, each_divisor, has_divisor?, divisor_of?
|
14
14
|
email:
|
@@ -26,7 +26,7 @@ files:
|
|
26
26
|
- Rakefile
|
27
27
|
- bin/console
|
28
28
|
- bin/setup
|
29
|
-
-
|
29
|
+
- idivisor.gemspec
|
30
30
|
- lib/idivisor.rb
|
31
31
|
- lib/idivisor/version.rb
|
32
32
|
homepage: https://github.com/universato/idivisor
|
@@ -35,7 +35,7 @@ licenses:
|
|
35
35
|
metadata:
|
36
36
|
homepage_uri: https://github.com/universato/idivisor
|
37
37
|
source_code_uri: https://github.com/universato/idivisor
|
38
|
-
post_install_message:
|
38
|
+
post_install_message:
|
39
39
|
rdoc_options: []
|
40
40
|
require_paths:
|
41
41
|
- lib
|
@@ -50,8 +50,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
|
-
rubygems_version: 3.
|
54
|
-
signing_key:
|
53
|
+
rubygems_version: 3.2.11
|
54
|
+
signing_key:
|
55
55
|
specification_version: 4
|
56
56
|
summary: divisor
|
57
57
|
test_files: []
|