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 +4 -4
- data/README.md +3 -0
- data/hash_order_helper.gemspec +1 -1
- data/lib/hash_order_helper.rb +22 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 278e89e8913fdbfe4e9cab86ed0fc9032b138b00
|
4
|
+
data.tar.gz: c74a334591c31d7b850d0fa773c0f4ceea6da16b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/hash_order_helper.gemspec
CHANGED
data/lib/hash_order_helper.rb
CHANGED
@@ -65,7 +65,7 @@ module HashOrderHelper
|
|
65
65
|
last_values
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
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
|
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(:
|
121
|
+
Hash.send(:prepend, HashOrderHelper)
|