hash-utils 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -4
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/hash-utils.gemspec +3 -3
- data/lib/hash-utils/array.rb +1 -1
- data/lib/hash-utils/hash.rb +40 -2
- data/test +7 -8
- metadata +4 -4
data/README.md
CHANGED
@@ -3,8 +3,7 @@ Hash Utils
|
|
3
3
|
|
4
4
|
**Hash Utils** adds a lot of useful fundamental utility methods which
|
5
5
|
are missing in Ruby, both to [Array][1] and [Hash][2] classes and
|
6
|
-
introduces some useful methods and syntactic sugar to [
|
7
|
-
[Symbol][6] and [String][8] classes too.
|
6
|
+
introduces some useful methods and syntactic sugar to [Object][6] and [String][8] classes too.
|
8
7
|
|
9
8
|
For full reference and methods lists, see **[documentation][3]**.
|
10
9
|
|
@@ -35,8 +34,7 @@ further details.
|
|
35
34
|
[1]: http://www.ruby-doc.org/core/classes/Array.html
|
36
35
|
[2]: http://www.ruby-doc.org/core/classes/Hash.html
|
37
36
|
[3]: http://rubydoc.info/gems/hash-utils
|
38
|
-
[6]: http://www.ruby-doc.org/core/classes/
|
39
|
-
[7]: http://www.ruby-doc.org/core/classes/Numeric.html
|
37
|
+
[6]: http://www.ruby-doc.org/core/classes/Object.html
|
40
38
|
[8]: http://www.ruby-doc.org/core/classes/String.html
|
41
39
|
[9]: http://github.com/martinkozak/hash-utils/issues
|
42
40
|
[10]: http://www.martinkozak.net/
|
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@ Jeweler::Tasks.new do |gem|
|
|
16
16
|
gem.name = "hash-utils"
|
17
17
|
gem.homepage = "http://github.com/martinkozak/hash-utils"
|
18
18
|
gem.license = "MIT"
|
19
|
-
gem.summary = 'Adds a lot of useful fundamental utility methods which are missing in Ruby, both to Array and Hash classes and introduces some useful methods and syntactic sugar to
|
19
|
+
gem.summary = 'Adds a lot of useful fundamental utility methods which are missing in Ruby, both to Array and Hash classes and introduces some useful methods and syntactic sugar to Object and String classes too.'
|
20
20
|
gem.email = "martinkozak@martinkozak.net"
|
21
21
|
gem.authors = ["Martin Kozák"]
|
22
22
|
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
data/hash-utils.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{hash-utils}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.9.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Martin Kozák"]
|
12
|
-
s.date = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-21}
|
13
13
|
s.email = %q{martinkozak@martinkozak.net}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
s.licenses = ["MIT"]
|
39
39
|
s.require_paths = ["lib"]
|
40
40
|
s.rubygems_version = %q{1.5.2}
|
41
|
-
s.summary = %q{Adds a lot of useful fundamental utility methods which are missing in Ruby, both to Array and Hash classes and introduces some useful methods and syntactic sugar to
|
41
|
+
s.summary = %q{Adds a lot of useful fundamental utility methods which are missing in Ruby, both to Array and Hash classes and introduces some useful methods and syntactic sugar to Object and String classes too.}
|
42
42
|
|
43
43
|
if s.respond_to? :specification_version then
|
44
44
|
s.specification_version = 3
|
data/lib/hash-utils/array.rb
CHANGED
@@ -92,7 +92,7 @@ class Array
|
|
92
92
|
# ["aa", "bb", "bb", "aa"].to_h(:flat)
|
93
93
|
#
|
94
94
|
# @param [Symbol] mode flat mode switch, can be +:flat+ or +nil+
|
95
|
-
# @return Hash new hash
|
95
|
+
# @return [Hash] new hash
|
96
96
|
# @see http://www.ruby-doc.org/core/classes/Hash.html#M000716
|
97
97
|
# @since 0.4.0
|
98
98
|
#
|
data/lib/hash-utils/hash.rb
CHANGED
@@ -153,7 +153,7 @@ class Hash
|
|
153
153
|
self.replace(self.map_pairs(&block))
|
154
154
|
end
|
155
155
|
|
156
|
-
alias :
|
156
|
+
alias :collect_pairs! :map_pairs!
|
157
157
|
|
158
158
|
##
|
159
159
|
# Returns a new hash with the results of running block once for
|
@@ -185,7 +185,7 @@ class Hash
|
|
185
185
|
self.replace(self.map_keys(&block))
|
186
186
|
end
|
187
187
|
|
188
|
-
alias :
|
188
|
+
alias :collect_keys! :map_keys!
|
189
189
|
|
190
190
|
##
|
191
191
|
# Converts all keys to symbols.
|
@@ -413,4 +413,42 @@ class Hash
|
|
413
413
|
self.replace(self.reverse)
|
414
414
|
end
|
415
415
|
|
416
|
+
##
|
417
|
+
# Indicates, all of the keys are available in Hash.
|
418
|
+
#
|
419
|
+
# @param [Array] keys objects for checking
|
420
|
+
# @return [Boolean] +true+ if yes, +false+ in otherwise
|
421
|
+
# @since 0.9.0
|
422
|
+
#
|
423
|
+
|
424
|
+
def has_all?(keys)
|
425
|
+
keys.each do |key|
|
426
|
+
if not self.has_key? key
|
427
|
+
return false
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
return true
|
432
|
+
end
|
433
|
+
|
434
|
+
alias :has_keys? :has_all?
|
435
|
+
|
436
|
+
##
|
437
|
+
# Indicates, some of the keys are available in Hash.
|
438
|
+
#
|
439
|
+
# @param [Array] keys objects for checking
|
440
|
+
# @return [Boolean] +true+ if yes, +false+ in otherwise
|
441
|
+
# @since 0.9.0
|
442
|
+
#
|
443
|
+
|
444
|
+
def has_some?(keys)
|
445
|
+
keys.each do |key|
|
446
|
+
if self.has_key? key
|
447
|
+
return true
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
return false
|
452
|
+
end
|
453
|
+
|
416
454
|
end
|
data/test
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
3
|
$:.push("./lib")
|
4
|
-
require "hash-utils/
|
5
|
-
foo = "bb aa cc aa dd"
|
4
|
+
require "hash-utils/hash"
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
puts
|
6
|
+
hash = {:a => 1, :b => 2}
|
7
|
+
puts hash.has_keys? [:a, :b]
|
8
|
+
puts hash.has_keys? [:a]
|
9
|
+
puts hash.has_keys? [:a, :c]
|
10
|
+
puts hash.has_some? [:a, :c]
|
11
|
+
puts hash.has_some? [:c]
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: hash-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.9.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Martin Koz\xC3\xA1k"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-21 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
76
|
requirements:
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
hash:
|
79
|
+
hash: -744753291499288812
|
80
80
|
segments:
|
81
81
|
- 0
|
82
82
|
version: "0"
|
@@ -92,6 +92,6 @@ rubyforge_project:
|
|
92
92
|
rubygems_version: 1.5.2
|
93
93
|
signing_key:
|
94
94
|
specification_version: 3
|
95
|
-
summary: Adds a lot of useful fundamental utility methods which are missing in Ruby, both to Array and Hash classes and introduces some useful methods and syntactic sugar to
|
95
|
+
summary: Adds a lot of useful fundamental utility methods which are missing in Ruby, both to Array and Hash classes and introduces some useful methods and syntactic sugar to Object and String classes too.
|
96
96
|
test_files: []
|
97
97
|
|