active_object 5.9.0 → 5.10.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.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/lib/active_object/integer.rb +13 -0
- data/lib/active_object/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7e4febce00f0b9055492157a80a17064a703650bf7eca0004e06d3c77af3399
|
4
|
+
data.tar.gz: 74e0446660a1c62734e2bef8d9184a4166aec98c0ae90aa2ac7c00767a00ed8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0191700a3c19bec3849c81865eb1bf4f8aeecc12ed2ddb05cbd8000e05e5d809c1989eed896b3f0bd1d603dfd5bff56c416fa2f6d9ae2e8e53b4a74fa573498c'
|
7
|
+
data.tar.gz: 75cba00734c57a78e0717d0599928217e5b9032cfab58302164f585e48b4cd8e5477babff68fd6323ca6b46c72305f9d7bb2614b9df4e7279092565762cf2ad8
|
data/README.md
CHANGED
@@ -851,12 +851,19 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
851
851
|
## Integer
|
852
852
|
|
853
853
|
**Factorial:**
|
854
|
-
`factorial`
|
854
|
+
`factorial` calculates the factorial of an integer.
|
855
855
|
|
856
856
|
```ruby
|
857
857
|
4.factorial #=> 24
|
858
858
|
```
|
859
859
|
|
860
|
+
**Factors:**
|
861
|
+
`factors` calculates all the factors of an integer.
|
862
|
+
|
863
|
+
```ruby
|
864
|
+
24.factors #=> [1, 24, 2, 12, 3, 8, 4, 6]
|
865
|
+
```
|
866
|
+
|
860
867
|
**Of:**
|
861
868
|
`of` is like #times but returns a collection of the yield results.
|
862
869
|
|
@@ -24,6 +24,19 @@ module ActiveObject
|
|
24
24
|
2.upto(self).inject(1) { |acc, elem| acc * elem }
|
25
25
|
end
|
26
26
|
|
27
|
+
def factors
|
28
|
+
limit = Math.sqrt(self).floor
|
29
|
+
|
30
|
+
(1..limit).each_with_object([]) do |i, acc|
|
31
|
+
next unless multiple_of?(i)
|
32
|
+
|
33
|
+
acc.push(i)
|
34
|
+
|
35
|
+
sq_num = (self / i)
|
36
|
+
acc.push(sq_num) if (sq_num) != i
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
27
40
|
def of(&block)
|
28
41
|
::Array.new(self, &block)
|
29
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|