hash-utils 0.12.0 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/hash-utils.gemspec +4 -3
- data/lib/hash-utils.rb +3 -2
- data/lib/hash-utils/hash.rb +1 -1
- data/lib/hash-utils/module.rb +34 -0
- data/lib/hash-utils/string.rb +1 -1
- data/lib/hash-utils/symbol.rb +24 -0
- data/test +15 -0
- metadata +5 -4
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Hash Utils
|
2
2
|
==========
|
3
3
|
|
4
|
-
**hash-utils** adds more than
|
4
|
+
**hash-utils** adds more than 67 useful and frequently rather
|
5
5
|
fundamental methods which are missing in Ruby programming language,
|
6
6
|
to several core classes. It tries to be similar project to
|
7
7
|
[Ruby Facets][1] on principle, but less complex, more practical,
|
@@ -10,9 +10,10 @@ non-atomic and organized by better way.
|
|
10
10
|
- `Array` – 3 methods,
|
11
11
|
- `File` – 2 methods,
|
12
12
|
- `Hash` – 30 methods,
|
13
|
+
- `Module` – 1 method,
|
13
14
|
- `Object` – 3 methods,
|
14
15
|
- `String` – 23 methods,
|
15
|
-
- `Symbol` –
|
16
|
+
- `Symbol` – 7 methods.
|
16
17
|
|
17
18
|
For full reference and methods lists, see **[documentation][3]**.
|
18
19
|
|
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 more than
|
19
|
+
gem.summary = 'Adds more than 67 useful and frequently rather fundamental methods which are missing in Ruby programming language, to Array, File, Hash, Module, Object, String and Symbol classes. It tries to be similar project to Ruby Facets on principle, but less complex, more practical, non-atomic and organized by better way.'
|
20
20
|
gem.post_install_message = "\nHASH UTILS: Be warn, Hash#all? is deprecated since version 0.10.0 because of\nconflict with built-in one with in fact equivalent functionallity. It will be\nremoved around version 0.13.0. Please, check your code if you can and switch\nto Ruby's one.\n\n"
|
21
21
|
gem.email = "martinkozak@martinkozak.net"
|
22
22
|
gem.authors = ["Martin Kozák"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.13.1
|
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.13.1"
|
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-03-
|
12
|
+
s.date = %q{2011-03-24}
|
13
13
|
s.email = %q{martinkozak@martinkozak.net}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/hash-utils/array.rb",
|
30
30
|
"lib/hash-utils/file.rb",
|
31
31
|
"lib/hash-utils/hash.rb",
|
32
|
+
"lib/hash-utils/module.rb",
|
32
33
|
"lib/hash-utils/numeric.rb",
|
33
34
|
"lib/hash-utils/object.rb",
|
34
35
|
"lib/hash-utils/string.rb",
|
@@ -46,7 +47,7 @@ to Ruby's one.
|
|
46
47
|
}
|
47
48
|
s.require_paths = ["lib"]
|
48
49
|
s.rubygems_version = %q{1.6.2}
|
49
|
-
s.summary = %q{Adds more than
|
50
|
+
s.summary = %q{Adds more than 67 useful and frequently rather fundamental methods which are missing in Ruby programming language, to Array, File, Hash, Module, Object, String and Symbol classes. It tries to be similar project to Ruby Facets on principle, but less complex, more practical, non-atomic and organized by better way.}
|
50
51
|
|
51
52
|
if s.respond_to? :specification_version then
|
52
53
|
s.specification_version = 3
|
data/lib/hash-utils.rb
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
3
|
|
4
4
|
require "hash-utils/array"
|
5
|
+
require "hash-utils/file"
|
5
6
|
require "hash-utils/hash"
|
6
|
-
require "hash-utils/
|
7
|
+
require "hash-utils/module"
|
7
8
|
require "hash-utils/object"
|
9
|
+
require "hash-utils/string"
|
8
10
|
require "hash-utils/symbol"
|
9
|
-
require "hash-utils/file"
|
data/lib/hash-utils/hash.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
##
|
5
|
+
# Module extension.
|
6
|
+
#
|
7
|
+
|
8
|
+
class Module
|
9
|
+
|
10
|
+
##
|
11
|
+
# Returns submodule or subclass recursively. It's approximately
|
12
|
+
# 3x faster than +Kernel#eval+.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# Kernel.get_module("Zlib::Inflate")
|
16
|
+
#
|
17
|
+
# @param [String] full class or module name
|
18
|
+
# @return [Module] required module
|
19
|
+
# @since 0.13.0
|
20
|
+
#
|
21
|
+
|
22
|
+
def get_module(name)
|
23
|
+
names = name.split("::")
|
24
|
+
mod = self
|
25
|
+
|
26
|
+
while not names.empty?
|
27
|
+
name = names.shift
|
28
|
+
mod = mod.const_get(name)
|
29
|
+
end
|
30
|
+
|
31
|
+
return mod
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/hash-utils/string.rb
CHANGED
data/lib/hash-utils/symbol.rb
CHANGED
@@ -73,5 +73,29 @@ class Symbol
|
|
73
73
|
def end_with?(*suffix)
|
74
74
|
self.to_s.end_with?(*suffix)
|
75
75
|
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Puts content to end of symbol and returns new symbol.
|
79
|
+
#
|
80
|
+
# @param [String] string string for append
|
81
|
+
# @return [Symbol] itself
|
82
|
+
# @since 0.13.0
|
83
|
+
#
|
84
|
+
|
85
|
+
def append(string)
|
86
|
+
(self.to_s << string.to_s).to_sym
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# Puts content to begin of symbol and returns new symbol.
|
91
|
+
#
|
92
|
+
# @param [String] string string for prepend
|
93
|
+
# @return [Symbol] itself
|
94
|
+
# @since 0.13.0
|
95
|
+
#
|
96
|
+
|
97
|
+
def prepend(string)
|
98
|
+
(string.to_s + self.to_s).to_sym
|
99
|
+
end
|
76
100
|
|
77
101
|
end
|
data/test
CHANGED
@@ -68,6 +68,15 @@ context "Hash" do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
## MODULE
|
72
|
+
|
73
|
+
context "Module" do
|
74
|
+
asserts("#get_module") do
|
75
|
+
require "zlib"
|
76
|
+
Kernel.get_module("Zlib::Inflate") == Zlib::Inflate
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
71
80
|
## OBJECT
|
72
81
|
|
73
82
|
context "Object" do
|
@@ -199,9 +208,15 @@ context "Symbol" do
|
|
199
208
|
asserts("#[]") do
|
200
209
|
:abcde[0...3] == "abc"
|
201
210
|
end
|
211
|
+
asserts("#append") do
|
212
|
+
:abcd.append("efg") == :abcdefg
|
213
|
+
end
|
202
214
|
asserts("#end_with?") do
|
203
215
|
:abcde.end_with? "ghi", "cde"
|
204
216
|
end
|
217
|
+
asserts("#prepend") do
|
218
|
+
:abcd.prepend("012") == :"012abcd"
|
219
|
+
end
|
205
220
|
asserts("#start_with?") do
|
206
221
|
:abcde.start_with? "ghi", "abc"
|
207
222
|
end
|
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.13.1
|
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-03-
|
13
|
+
date: 2011-03-24 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/hash-utils/array.rb
|
70
70
|
- lib/hash-utils/file.rb
|
71
71
|
- lib/hash-utils/hash.rb
|
72
|
+
- lib/hash-utils/module.rb
|
72
73
|
- lib/hash-utils/numeric.rb
|
73
74
|
- lib/hash-utils/object.rb
|
74
75
|
- lib/hash-utils/string.rb
|
@@ -92,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
93
|
requirements:
|
93
94
|
- - ">="
|
94
95
|
- !ruby/object:Gem::Version
|
95
|
-
hash: -
|
96
|
+
hash: -246920346278119187
|
96
97
|
segments:
|
97
98
|
- 0
|
98
99
|
version: "0"
|
@@ -108,6 +109,6 @@ rubyforge_project:
|
|
108
109
|
rubygems_version: 1.6.2
|
109
110
|
signing_key:
|
110
111
|
specification_version: 3
|
111
|
-
summary: Adds more than
|
112
|
+
summary: Adds more than 67 useful and frequently rather fundamental methods which are missing in Ruby programming language, to Array, File, Hash, Module, Object, String and Symbol classes. It tries to be similar project to Ruby Facets on principle, but less complex, more practical, non-atomic and organized by better way.
|
112
113
|
test_files: []
|
113
114
|
|