nuggets 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +5 -1
- data/README +1 -1
- data/lib/nuggets/hash/nest_mixin.rb +36 -2
- data/lib/nuggets/version.rb +2 -2
- data/spec/nuggets/hash/nest_spec.rb +43 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89f2d47d5e501cd0800f31bd572cdd1c20c6e98c
|
4
|
+
data.tar.gz: c69f1ac6fc489329f61e96fb419c63f5180bf5c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24d1c8c645c8d9ef912e30a82dea599744d986ea5254947cfea0598457f9943328f239cb59264fb43dfab9148f2627a40ca7648cdd9b7a756c1aa66acac32233
|
7
|
+
data.tar.gz: c503ac3652caedcf02c85353a4098ddfaa26a933af2fd5ac73ac3e53be5c71022cbf2498bd48b3654247db36c05b710b5dfae762343347dffbfc6248fd5be9be
|
data/ChangeLog
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
= Revision history for nuggets
|
4
4
|
|
5
|
+
== 1.3.0 [2015-07-07]
|
6
|
+
|
7
|
+
* Added <tt>Hash.{identity,array}</tt>.
|
8
|
+
|
5
9
|
== 1.2.1 [2015-04-14]
|
6
10
|
|
7
11
|
* Ruby Core compatibility for Enumerable#minmax etc. Issue #4 by @codez.
|
@@ -10,7 +14,7 @@
|
|
10
14
|
|
11
15
|
* Extracted Nuggets::RubyMixin from Nuggets::Ruby.
|
12
16
|
* Added Net::SSH::Connection::Session#exec_sudo.
|
13
|
-
* Added Hash
|
17
|
+
* Added Hash#deproc.
|
14
18
|
|
15
19
|
== 1.1.0 [2014-11-26]
|
16
20
|
|
data/README
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# #
|
4
4
|
# nuggets -- Extending Ruby #
|
5
5
|
# #
|
6
|
-
# Copyright (C) 2007-
|
6
|
+
# Copyright (C) 2007-2015 Jens Wille #
|
7
7
|
# #
|
8
8
|
# Authors: #
|
9
9
|
# Jens Wille <jens.wille@gmail.com> #
|
@@ -44,7 +44,7 @@ module Nuggets
|
|
44
44
|
#
|
45
45
|
# Example:
|
46
46
|
#
|
47
|
-
# hash = Hash.nest(
|
47
|
+
# hash = Hash.nest(2)
|
48
48
|
# hash[:foo][:bar][:a] = { :x => 1, :y => 2 }
|
49
49
|
# hash[:foo][:bar][:b] = { :x => 0, :y => 3 }
|
50
50
|
# hash
|
@@ -73,6 +73,40 @@ module Nuggets
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
# call-seq:
|
77
|
+
# Hash.identity([depth]) => aHash
|
78
|
+
#
|
79
|
+
# Creates a nested hash, +depth+ levels deep, that yields the keys
|
80
|
+
# themselves at the last level.
|
81
|
+
#
|
82
|
+
# Example:
|
83
|
+
#
|
84
|
+
# hash = Hash.identity(2)
|
85
|
+
# hash[:foo][:bar][:a] #=> :a
|
86
|
+
# hash[:foo][:bar][:b] #=> :b
|
87
|
+
# hash
|
88
|
+
# #=> {:foo=>{:bar=>{:a=>:a, :b=>:b}}}
|
89
|
+
def identity(depth = 0)
|
90
|
+
nest(depth) { |key| key }
|
91
|
+
end
|
92
|
+
|
93
|
+
# call-seq:
|
94
|
+
# Hash.array([depth]) => aHash
|
95
|
+
#
|
96
|
+
# Creates a nested hash, +depth+ levels deep, that yields arrays
|
97
|
+
# at the last level.
|
98
|
+
#
|
99
|
+
# Example:
|
100
|
+
#
|
101
|
+
# hash = Hash.array(2)
|
102
|
+
# hash[:foo][:bar][:a] << 1 << 2
|
103
|
+
# hash[:foo][:bar][:b] << 3 << 4
|
104
|
+
# hash
|
105
|
+
# #=> {:foo=>{:bar=>{:a=>[1, 2], :b=>[3, 4]}}}
|
106
|
+
def array(depth = 0)
|
107
|
+
nest(depth) { [] }
|
108
|
+
end
|
109
|
+
|
76
110
|
end
|
77
111
|
end
|
78
112
|
end
|
data/lib/nuggets/version.rb
CHANGED
@@ -99,4 +99,47 @@ describe_extended Hash, Nuggets::Hash::NestMixin, true do
|
|
99
99
|
hash[:a][:b][:c].should have_key(:e)
|
100
100
|
end
|
101
101
|
|
102
|
+
example do
|
103
|
+
hash = Hash.identity
|
104
|
+
hash.should be_an_instance_of(Hash)
|
105
|
+
|
106
|
+
hash[:a].should == :a
|
107
|
+
hash[:b].should == :b
|
108
|
+
|
109
|
+
hash.should == { a: :a, b: :b }
|
110
|
+
end
|
111
|
+
|
112
|
+
example do
|
113
|
+
hash = Hash.identity(2)
|
114
|
+
hash.should be_an_instance_of(Hash)
|
115
|
+
|
116
|
+
hash[:foo][:bar][:a].should == :a
|
117
|
+
hash[:foo][:bar][:b].should == :b
|
118
|
+
|
119
|
+
hash.should == { foo: { bar: { a: :a, b: :b } } }
|
120
|
+
end
|
121
|
+
|
122
|
+
example do
|
123
|
+
hash = Hash.array
|
124
|
+
hash.should be_an_instance_of(Hash)
|
125
|
+
|
126
|
+
hash[:a].should be_an_instance_of(Array)
|
127
|
+
hash[:a].push(1).push(2).should == [1, 2]
|
128
|
+
|
129
|
+
hash[:b].should be_an_instance_of(Array)
|
130
|
+
hash[:b].push(3).push(4).should == [3, 4]
|
131
|
+
|
132
|
+
hash.should == { a: [1, 2], b: [3, 4] }
|
133
|
+
end
|
134
|
+
|
135
|
+
example do
|
136
|
+
hash = Hash.array(2)
|
137
|
+
hash.should be_an_instance_of(Hash)
|
138
|
+
|
139
|
+
hash[:foo][:bar][:a].push(1).push(2).should == [1, 2]
|
140
|
+
hash[:foo][:bar][:b].push(3).push(4).should == [3, 4]
|
141
|
+
|
142
|
+
hash.should == { foo: { bar: { a: [1, 2], b: [3, 4] } } }
|
143
|
+
end
|
144
|
+
|
102
145
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nuggets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Wille
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mime-types
|
@@ -349,13 +349,13 @@ licenses:
|
|
349
349
|
metadata: {}
|
350
350
|
post_install_message: |2+
|
351
351
|
|
352
|
-
nuggets-1.
|
352
|
+
nuggets-1.3.0 [2015-07-07]:
|
353
353
|
|
354
|
-
*
|
354
|
+
* Added <tt>Hash.{identity,array}</tt>.
|
355
355
|
|
356
356
|
rdoc_options:
|
357
357
|
- "--title"
|
358
|
-
- nuggets Application documentation (v1.
|
358
|
+
- nuggets Application documentation (v1.3.0)
|
359
359
|
- "--charset"
|
360
360
|
- UTF-8
|
361
361
|
- "--line-numbers"
|
@@ -376,7 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
376
376
|
version: '0'
|
377
377
|
requirements: []
|
378
378
|
rubyforge_project:
|
379
|
-
rubygems_version: 2.4.
|
379
|
+
rubygems_version: 2.4.8
|
380
380
|
signing_key:
|
381
381
|
specification_version: 4
|
382
382
|
summary: Extending Ruby.
|