kirinnee_core 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -1
- data/lib/kirinnee_core.rb +1 -0
- data/lib/kirinnee_core/hash.rb +46 -0
- data/lib/kirinnee_core/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3619535c8bc70a8a81092a180e97fe491bdb0907ba2707e84bdcdf3ac0bb1d1
|
4
|
+
data.tar.gz: 0e2f1998a8a5e158f4e331a755a777cadca751dd40456a4654aa5e7f4f71141d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d39105682f6d3aa207ef513397c1c30595bd54edc6f0e10e5ebba341bf90ab3d791d73613a445f182d107c429ec4d1cb96406c53b5bb55c3b837974b71684a1
|
7
|
+
data.tar.gz: 3e2c2f00e1c7d77de860d72c1b3518a932d16d64ab22012d60e91fcb56765d1b3627cb6d1a9ce429ecd9a27b808511d8cf341cb2a86938967cafe49cf9e3bc61
|
data/README.md
CHANGED
@@ -351,8 +351,40 @@ Counts the number of times a string appears
|
|
351
351
|
"one day one night one".count_occurrences "one" # => 3
|
352
352
|
```
|
353
353
|
|
354
|
-
|
354
|
+
### String
|
355
|
+
Here are the monkey patched methods for Strings
|
356
|
+
|
357
|
+
___
|
358
|
+
##### without_key `without`
|
359
|
+
Remove all pairs with the key in the supplied array
|
360
|
+
|
361
|
+
Does not mutate the original hash
|
362
|
+
```ruby
|
363
|
+
{:a => 1, :b => 2, :c => 3, :d => 4}.without_key [:a, :b] #=> {:c => 3, :d => 4}
|
364
|
+
```
|
365
|
+
##### without_key! `without`
|
366
|
+
Remove all pairs with the key in the supplied array
|
367
|
+
|
368
|
+
Mutates the original hash
|
369
|
+
```ruby
|
370
|
+
{:a => 1, :b => 2, :c => 3, :d => 4}.without_key! [:a, :b] #=> {:c => 3, :d => 4}
|
371
|
+
```
|
372
|
+
|
373
|
+
##### without_value `without`
|
374
|
+
Remove all pairs with the value in the supplied array
|
375
|
+
|
376
|
+
Does not mutate the original hash
|
377
|
+
```ruby
|
378
|
+
{:a => 1, :b => 2, :c => 3, :d => 4, :e => 1}.without_value [1, 2] #=> {:c => 3, :d => 4}
|
379
|
+
```
|
380
|
+
|
381
|
+
##### without_value `without`
|
382
|
+
Remove all pairs with the value in the supplied array
|
355
383
|
|
384
|
+
Mutate the original hash
|
385
|
+
```ruby
|
386
|
+
{:a => 1, :b => 2, :c => 3, :d => 4, :e => 1}.without_value! [1, 2] #=> {:c => 3, :d => 4}
|
387
|
+
```
|
356
388
|
|
357
389
|
## Development
|
358
390
|
|
data/lib/kirinnee_core.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
class Hash
|
2
|
+
|
3
|
+
# Remove all paris with the key in the supplied array
|
4
|
+
# Does not mutate the original hash
|
5
|
+
#
|
6
|
+
# {:a => 1, :b => 2, :c => 3, :d => 4}.without_key [:a, :b] #=> {:c => 3, :d => 4}
|
7
|
+
#
|
8
|
+
# @param [Array] keys the keys to remove
|
9
|
+
# @return [Hash]
|
10
|
+
def without_key(keys)
|
11
|
+
select {|k| !keys.has? k}.to_h
|
12
|
+
end
|
13
|
+
|
14
|
+
# Remove all pairs with the key in the supplied array
|
15
|
+
# Mutates the original hash
|
16
|
+
#
|
17
|
+
# {:a => 1, :b => 2, :c => 3, :d => 4}.without_key! [:a, :b] #=> {:c => 3, :d => 4}
|
18
|
+
#
|
19
|
+
# @param [Array] keys the keys to remove
|
20
|
+
# @return [Hash]
|
21
|
+
def without_key!(keys)
|
22
|
+
select! {|k| !keys.has? k}.to_h
|
23
|
+
end
|
24
|
+
|
25
|
+
# Remove all pairs with the value in the supplied array
|
26
|
+
# Does not mutate the original hash
|
27
|
+
#
|
28
|
+
# {:a => 1, :b => 2, :c => 3, :d => 4, :e => 1}.without_value [1, 2] #=> {:c => 3, :d => 4}
|
29
|
+
#
|
30
|
+
# @param [Array] values the values to remove
|
31
|
+
# @return [Hash]
|
32
|
+
def without_value(values)
|
33
|
+
select {|_, v| !values.has? v}.to_h
|
34
|
+
end
|
35
|
+
|
36
|
+
# Remove all pairs with the value in the supplied array
|
37
|
+
# Mutate the original hash
|
38
|
+
#
|
39
|
+
# {:a => 1, :b => 2, :c => 3, :d => 4, :e => 1}.without_value! [1, 2] #=> {:c => 3, :d => 4}
|
40
|
+
#
|
41
|
+
# @param [Array] values the values to remove
|
42
|
+
# @return [Hash]
|
43
|
+
def without_value!(values)
|
44
|
+
select! {|_, v| !values.has? v}.to_h
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kirinnee_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kirinnee
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- kirinnee_core.gemspec
|
79
79
|
- lib/kirinnee_core.rb
|
80
80
|
- lib/kirinnee_core/enumerable.rb
|
81
|
+
- lib/kirinnee_core/hash.rb
|
81
82
|
- lib/kirinnee_core/string.rb
|
82
83
|
- lib/kirinnee_core/version.rb
|
83
84
|
homepage: https://gitlab.com/ruby-gem/kirinnee-core
|