hash_order_helper 0.1.3 → 0.1.4

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: 816648a641f45835c25e16f103cdc7dab96b0649
4
- data.tar.gz: 7157b16ce4d46d84992d637d6b512733ef06a2cb
3
+ metadata.gz: 278e89e8913fdbfe4e9cab86ed0fc9032b138b00
4
+ data.tar.gz: c74a334591c31d7b850d0fa773c0f4ceea6da16b
5
5
  SHA512:
6
- metadata.gz: 189374b3518cc32b0776d0d5d1189433284f58d5c47fb0768f40bc8aed2a909b39687c347a536efcd8a04e11242f07354a8b4a81bdf7a04c74932a2b6175dfc1
7
- data.tar.gz: 048161554f245df847ddd29890e53f4fff9525d3ad3f33b031178a3513d1909affde523f959af357a260d9776a977c2e64d20a1d6384347af93c5eec86bfb521
6
+ metadata.gz: eb3d0c7868e9386b09233057ade12c935ba9a3ad910cd887b79d529f59e957a5e940b29e71c8da0192a55af7de548a95e276507b0a203b54f5d0ca0ac72ffb29
7
+ data.tar.gz: 444e68e8e0b3d07f46938171a2011225f2bcd26a407116f82bd31ffb2f9e60e49b479d7fa0a996d32f7b4a6942e1988834d512e2bf382d456c5b4aa4e52e6070
data/README.md CHANGED
@@ -46,9 +46,12 @@ The following methods are added:
46
46
  * `last(n) -> Array`
47
47
  * `pop -> Array`
48
48
  * `pop(n) -> Array` (alias: `<<`)
49
+ * `nd_push(hash) -> Hash` **non-destructive** (alias: `<`)
49
50
  * `push(hash) -> Hash`
51
+ * `nd_unshift(hash) -> Hash` **non-destructive**
50
52
  * `unshift(hash) -> Hash`
51
53
  * `>>(receiver_hash) -> Hash`
54
+ * `>(receiver_hash) -> Hash` **non-destructive**
52
55
 
53
56
  ### `>>` method
54
57
 
@@ -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.3'
4
+ spec.version = '0.1.4'
5
5
  spec.authors = ['Genki Sugawara']
6
6
  spec.email = ['sugawara@cookpad.com']
7
7
 
@@ -65,7 +65,7 @@ module HashOrderHelper
65
65
  last_values
66
66
  end
67
67
 
68
- def push(push_hash)
68
+ def nd_push(push_hash)
69
69
  hash_keys = self.keys - push_hash.keys
70
70
  hash_keys.push(*push_hash.keys)
71
71
  new_hash = {}
@@ -74,11 +74,17 @@ module HashOrderHelper
74
74
  new_hash[key] = value
75
75
  end
76
76
 
77
+ new_hash
78
+ end
79
+ alias < nd_push
80
+
81
+ def push(push_hash)
82
+ new_hash = nd_push(push_hash)
77
83
  self.replace(new_hash)
78
84
  end
79
85
  alias << push
80
86
 
81
- def unshift(unshift_hash)
87
+ def nd_unshift(unshift_hash)
82
88
  hash_keys = self.keys - unshift_hash.keys
83
89
  hash_keys.unshift(*unshift_hash.keys)
84
90
  new_hash = {}
@@ -88,6 +94,11 @@ module HashOrderHelper
88
94
  new_hash[key] = value
89
95
  end
90
96
 
97
+ new_hash
98
+ end
99
+
100
+ def unshift(unshift_hash)
101
+ new_hash = nd_unshift(unshift_hash)
91
102
  self.replace(new_hash)
92
103
  end
93
104
 
@@ -98,5 +109,13 @@ module HashOrderHelper
98
109
 
99
110
  receiver.unshift(self)
100
111
  end
112
+
113
+ def >(receiver)
114
+ unless receiver.is_a?(Hash)
115
+ raise TypeError, "no implicit conversion of #{receiver.inspect}:#{receiver.class} into Hash"
116
+ end
117
+
118
+ receiver.nd_unshift(self)
119
+ end
101
120
  end
102
- Hash.send(:include, HashOrderHelper)
121
+ Hash.send(:prepend, HashOrderHelper)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_order_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara