active_object 5.9.0 → 5.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 881c56690618f36c3f9a10fe57d8effb72a0d3674c37e59902bb81a71f9b4a17
4
- data.tar.gz: 8a93ffd7957d9b8cf7d49e30a34bed2273e5c9206e2eb79b0120df940aa16f5d
3
+ metadata.gz: d7e4febce00f0b9055492157a80a17064a703650bf7eca0004e06d3c77af3399
4
+ data.tar.gz: 74e0446660a1c62734e2bef8d9184a4166aec98c0ae90aa2ac7c00767a00ed8a
5
5
  SHA512:
6
- metadata.gz: 16450952ceb4a3514a5b2c3adfe215aec0c0460ef06c93e73689d9109134af035418c1bcc327698ec7c3909af849e82adeb97cd6cc40de4094cacd9d6ff54ec6
7
- data.tar.gz: 57644c5ec814a62ce95d731f8fdd4ca6fb21d241ea4a3dd273bff0b7afb48a4bc57617dd963ff526867bb4e07a8b8c112f3f487e1632763ed996889d07b9d717
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` calculate the factorial of an integer.
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveObject
4
- VERSION ||= '5.9.0'
4
+ VERSION ||= '5.10.0'
5
5
  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.9.0
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-06 00:00:00.000000000 Z
11
+ date: 2019-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler