hash_order_helper 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 874e46ded6285d9b4e7b9f736bd0e9f4f4fed0b8
4
- data.tar.gz: 9dcf80f01337d10dc53a7e793d81211025345ca0
3
+ metadata.gz: f9525f6b741b4bc89963ed09244662eee18133aa
4
+ data.tar.gz: 5b814deff9182fcd07e653cdda9b7830cdee6b6c
5
5
  SHA512:
6
- metadata.gz: 910d7c5e8076c6928f8474c7646c089c09b15623d3a46f1a1ea955399a62d5eafb33eed2c6e0073ae9549826afe58807bf0aeff38be2fa036e6325aa92322a8f
7
- data.tar.gz: 82d8420f672d64ec300c8b80cae356277cbaf9ed3cd4dab6c0c73365bb3fe5eb4c204060d563b3dac31bbe3b9e980d260b55c9ec78160dafdd97f55424001746
6
+ metadata.gz: 61e7fe158b6bad7e54f8087617c83367cbef2f5d18d2c7f3d9a0a198538f5afd6e135178d10fda46a484a70fd144f60e6c21f142e5beeeefc073afd7ca50f950
7
+ data.tar.gz: d8cdefbbff3d7419f03c1737f352d0a35699bc489dddc6609f5e7bf97861094e809c9948d1da00ea8636b3b7e849523cc3906965f5e169db8bc9ae0ecb097284
data/README.md CHANGED
@@ -30,7 +30,7 @@ hash = {b: 200, a: 100, c: 150}
30
30
  hash.sort_pair
31
31
  #=> {:a=>100, :b=>200, :c=>150}
32
32
 
33
- hash.unshift(:d, 300)
33
+ hash.unshift(d: 300)
34
34
  #=> {:d=>300, :b=>200, :a=>100, :c=>150}
35
35
  ```
36
36
 
@@ -41,10 +41,10 @@ The following methods are added:
41
41
  * `sort_pair_by {|key, value| ... } -> Hash`
42
42
  * `sort_pair_by! {|key, value| ... } -> Hash`
43
43
  * `at(nth) -> Array`
44
- * `insert(nth, key, value) -> Hash`
44
+ * `insert(nth, hash) -> Hash`
45
45
  * `last -> Array`
46
46
  * `last(n) -> Array`
47
47
  * `pop -> Array`
48
48
  * `pop(n) -> Array`
49
- * `push(key, value) -> Hash`
50
- * `unshift(key, value) -> Hash`
49
+ * `push(hash) -> Hash`
50
+ * `unshift(hash) -> Hash`
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = 'hash_order_helper'
4
- spec.version = '0.1.0'
4
+ spec.version = '0.1.1'
5
5
  spec.authors = ['Genki Sugawara']
6
6
  spec.email = ['sugawara@cookpad.com']
7
7
 
@@ -31,13 +31,13 @@ module HashOrderHelper
31
31
  self.to_a.at(nth)
32
32
  end
33
33
 
34
- def insert(nth, new_key, new_value)
34
+ def insert(nth, insert_hash)
35
35
  hash_keys = self.keys
36
- hash_keys.insert(nth, new_key)
36
+ hash_keys.insert(nth, *insert_hash.keys)
37
37
  new_hash = {}
38
38
 
39
39
  hash_keys.each do |key|
40
- value = (key == new_key) ? new_value : self[key]
40
+ value = insert_hash.has_key?(key) ? insert_hash[key] : self[key]
41
41
  new_hash[key] = value
42
42
  end
43
43
 
@@ -65,26 +65,25 @@ module HashOrderHelper
65
65
  last_values
66
66
  end
67
67
 
68
- def push(new_key, new_value)
68
+ def push(push_hash)
69
69
  hash_keys = self.keys
70
- hash_keys.push(new_key)
70
+ hash_keys.push(*push_hash.keys)
71
71
  new_hash = {}
72
-
73
72
  hash_keys.each do |key|
74
- value = (key == new_key) ? new_value : self[key]
73
+ value = push_hash.has_key?(key) ? push_hash[key] : self[key]
75
74
  new_hash[key] = value
76
75
  end
77
76
 
78
77
  self.replace(new_hash)
79
78
  end
80
79
 
81
- def unshift(new_key, new_value)
80
+ def unshift(unshift_hash)
82
81
  hash_keys = self.keys
83
- hash_keys.unshift(new_key)
82
+ hash_keys.unshift(*unshift_hash.keys)
84
83
  new_hash = {}
85
84
 
86
85
  hash_keys.each do |key|
87
- value = (key == new_key) ? new_value : self[key]
86
+ value = unshift_hash.has_key?(key) ? unshift_hash[key] : self[key]
88
87
  new_hash[key] = value
89
88
  end
90
89
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_order_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-10 00:00:00.000000000 Z
11
+ date: 2016-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler