lite-ruby 1.0.15 → 1.0.16

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: a56a9fed1ae0986131374f5cc62aeb0ff75db166a63bbb91a6530cbf15ac6ccc
4
- data.tar.gz: f8f29474d5b6e38f978304278a442e96b6d1c98dd685bc234db1823c9452f67d
3
+ metadata.gz: 997db962e2187aad31324a203ccd2d9e356d4a18d02b80e24bdc32c7e433e95b
4
+ data.tar.gz: 9e9b55dca2fea604b0e58e8e750dda082bfc9851ce3c5004f4451afe64468336
5
5
  SHA512:
6
- metadata.gz: 96f161d9040d4247cc924ccdea3318412828174ba2972e3a445faa0f0cfe7cd8e3ce71870420d78dbd884aa518f3cba467ace1507bf38c65787da3793903b0b1
7
- data.tar.gz: 1498b714da8ea3a2f3a8ac542cf77f42e574bd1dadbe3a066e02bbaef9d012ec7f18b55cc29ede07aee4fdf5c95a3ef559b5eea67130e7baa1378daaaac4f35f
6
+ metadata.gz: bac9fa22759bd3c30f9596a3906f70e089a99ef8cfcc3eee478f0992fdde84b7d7b069fa185c04b6e1dce5ca8e82602c95c338a7eebf6a212f60f7ba2c6cb146
7
+ data.tar.gz: a33333716041baaabea38cb8ab2a307f3c587c6988c5d2628e734503c67ee4a10765e150d836cd666a1b2c03a97bff2b5678d5bf6457d05aaf1a135ad88d96f3
data/CHANGELOG.md CHANGED
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.16] - 2019-08-18
10
+ ### Added
11
+ - Added Array => `deep_dup`
12
+ - Added Hash => `deep_dup`
13
+ - Added Integer => `combinatorial`
14
+ - Added Numeric => `round_down`
15
+ - Added Object => `deep_dup`
16
+ ### Changed
17
+ - Changed how integer factorial works
18
+
9
19
  ## [1.0.15] - 2019-08-17
10
20
  ### Changed
11
21
  - Added config check for each monkey patch
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (1.0.15)
4
+ lite-ruby (1.0.16)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/docs/INTEGER.md CHANGED
@@ -45,11 +45,23 @@ Returns if it is a bitmask set.
45
45
  8.bitmask?(2) #=> false
46
46
  ```
47
47
 
48
+ `combinatorial`
49
+ ------
50
+ Calculates the combinatorial of an integer to another integer.
51
+
52
+ ```ruby
53
+ 50.combinatorial(49) #=> 50
54
+ 50.combinatorial(50) #=> 1
55
+ 8.combinatorial(4) #=> 70
56
+ ```
57
+
48
58
  `factorial`
49
59
  ------
50
60
  Calculates the factorial of an integer.
51
61
 
52
62
  ```ruby
63
+ 0.factorial #=> 0
64
+ 1.factorial #=> 1
53
65
  4.factorial #=> 24
54
66
  ```
55
67
 
data/docs/NUMERIC.md CHANGED
@@ -292,6 +292,16 @@ Returns the nth root of a number.
292
292
  4.root(2) #=> 2
293
293
  ```
294
294
 
295
+ `round_down`
296
+ ------
297
+ Returns a number rounded down to given value.
298
+
299
+ ```ruby
300
+ 2.128.round_down #=> 2.0
301
+ 2.128.round_down(2) #=> 2.12
302
+ 2.round_down(2) #=> 2.0
303
+ ```
304
+
295
305
  `subtract`
296
306
  ------
297
307
  Returns the difference of two numbers.
@@ -57,6 +57,10 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
57
57
  # rubocop:enable Metrics/PerceivedComplexity, Style/GuardClause, Style/IfInsideElse
58
58
  # rubocop:enable Metrics/AbcSize, Metrics/BlockNesting, Metrics/MethodLength
59
59
 
60
+ def deep_dup
61
+ map(&:deep_dup)
62
+ end
63
+
60
64
  def delete_first
61
65
  self[1..-1]
62
66
  end
@@ -123,6 +123,23 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
123
123
  replace(dearray_singular_values)
124
124
  end
125
125
 
126
+ # rubocop:disable Style/CaseEquality
127
+ def deep_dup
128
+ hash = dup
129
+
130
+ each_pair do |key, value|
131
+ if key.frozen? && ::String === key
132
+ hash[key] = value.deep_dup
133
+ else
134
+ hash.delete(key)
135
+ hash[key.deep_dup] = value.deep_dup
136
+ end
137
+ end
138
+
139
+ hash
140
+ end
141
+ # rubocop:enable Style/CaseEquality
142
+
126
143
  def deep_merge(other_hash, &block)
127
144
  dup.deep_merge!(other_hash, &block)
128
145
  end
@@ -40,10 +40,12 @@ if Lite::Ruby.configuration.monkey_patches.include?('integer')
40
40
  (self & mask) != 0
41
41
  end
42
42
 
43
- def factorial
44
- return 1 if zero?
43
+ def combinatorial(num)
44
+ (0...num).inject(1) { |acc, i| (acc * (self - i)) / (i + 1) }
45
+ end
45
46
 
46
- 2.upto(self).inject(1) { |acc, i| acc * i }
47
+ def factorial
48
+ (1..self).inject { |acc, i| acc * i } || 0
47
49
  end
48
50
 
49
51
  def factors
@@ -214,6 +214,12 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
214
214
  self**(1.0 / num)
215
215
  end
216
216
 
217
+ def round_down(num = 0)
218
+ int, dec = to_f.to_s.split('.')
219
+
220
+ "#{int}.#{dec[0...num]}".to_f
221
+ end
222
+
217
223
  def subtract(num)
218
224
  self - num
219
225
  end
@@ -35,6 +35,14 @@ if Lite::Ruby.configuration.monkey_patches.include?('object')
35
35
  is_a?(Date)
36
36
  end
37
37
 
38
+ def deep_dup
39
+ duplicable? ? dup : self
40
+ end
41
+
42
+ def duplicable?
43
+ true
44
+ end
45
+
38
46
  # rubocop:disable Style/YodaCondition
39
47
  def false?
40
48
  false == self
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION ||= '1.0.15'
6
+ VERSION ||= '1.0.16'
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.15
4
+ version: 1.0.16
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-08-17 00:00:00.000000000 Z
11
+ date: 2019-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler