hash-utils 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ 2.0.1 (2012-08-26)
3
+ * Object: #enumerable?
4
+ * Hash: #flip, #flip!
5
+ * readme correction
6
+
2
7
  2.0.0 (2012-03-15)
3
8
  * defensive (safe) class patching
4
9
  * Array: #to_set
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Hash Utils
2
2
  ==========
3
3
 
4
- **hash-utils** adds more than 125 useful and frequently rather
4
+ **hash-utils** adds more than 135 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,
@@ -11,12 +11,12 @@ non-atomic and organized by better way.
11
11
  - `FalseClass` – 3 methods,
12
12
  - `File` – 2 methods,
13
13
  - `Gem` – 2 methods,
14
- - `Hash` – 40 methods,
14
+ - `Hash` – 42 methods,
15
15
  - `IO` – 1 method,
16
16
  - `Module` – 1 method,
17
17
  - `NilClass` – 1 method,
18
18
  - `Numeric` – 5 method,
19
- - `Object` – 14 methods,
19
+ - `Object` – 15 methods,
20
20
  - `Proc` – 1 method,
21
21
  - `TrueClass` – 3 methods,
22
22
  - `String` – 37 methods,
@@ -32,11 +32,7 @@ to appropriate type only by including the:
32
32
 
33
33
  require "hash-utils/<lowercase-data-type-name>"
34
34
 
35
- ### Special Requirements
36
-
37
- Some methods are optimized at Ruby 1.8.7 and 1.9 and higher. These
38
- optimizations requires the [`ruby-version`][2] gem available.
39
-
35
+
40
36
  Contributing
41
37
  ------------
42
38
 
data/Rakefile CHANGED
@@ -18,8 +18,8 @@ Jeweler::Tasks.new do |gem|
18
18
  gem.name = "hash-utils"
19
19
  gem.homepage = "http://github.com/martinkozak/hash-utils"
20
20
  gem.license = "MIT"
21
- gem.summary = 'Adds more than 125 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. Thanks to defensive and careful patching it should be compatible with all other libraries.'
22
- gem.post_install_message = "\nHASH UTILS: The 2.0 version avoids the method overwriting conflicts by not performing overwriting of already implemented methods. By this way, it can damage your existing applications based on older versions although it's very improbable. \n\n"
21
+ gem.summary = 'Adds more than 135 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. Thanks to defensive and careful patching it should be compatible with all other libraries.'
22
+ #gem.post_install_message = "\nHASH UTILS: The 2.0 version avoids the method overwriting conflicts by not performing overwriting of already implemented methods. By this way, it can damage your existing applications based on older versions although it's very improbable. \n\n"
23
23
  gem.email = "martinkozak@martinkozak.net"
24
24
  gem.authors = ["Martin Kozák"]
25
25
  # Include your dependencies below. Runtime dependencies are required when using your gem,
data/TODO.txt CHANGED
@@ -1,2 +1,3 @@
1
1
  * add examples to each call
2
2
  * write riot tests
3
+ * integrate functions from http://rubydoc.info/gems/sane/0.25.5/frames
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.0.1
data/hash-utils.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "hash-utils"
8
- s.version = "2.0.0"
8
+ s.version = "2.0.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\u{e1}k"]
12
- s.date = "2012-03-15"
12
+ s.date = "2012-08-26"
13
13
  s.email = "martinkozak@martinkozak.net"
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -45,10 +45,9 @@ Gem::Specification.new do |s|
45
45
  ]
46
46
  s.homepage = "http://github.com/martinkozak/hash-utils"
47
47
  s.licenses = ["MIT"]
48
- s.post_install_message = "\nHASH UTILS: The 2.0 version avoids the method overwriting conflicts by not performing overwriting of already implemented methods. By this way, it can damage your existing applications based on older versions although it's very improbable. \n\n"
49
48
  s.require_paths = ["lib"]
50
- s.rubygems_version = "1.8.17"
51
- s.summary = "Adds more than 125 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. Thanks to defensive and careful patching it should be compatible with all other libraries."
49
+ s.rubygems_version = "1.8.24"
50
+ s.summary = "Adds more than 135 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. Thanks to defensive and careful patching it should be compatible with all other libraries."
52
51
 
53
52
  if s.respond_to? :specification_version then
54
53
  s.specification_version = 3
@@ -824,5 +824,31 @@ class Hash
824
824
  true
825
825
  end
826
826
  end
827
-
827
+
828
+ ##
829
+ # Flips keys and values.
830
+ #
831
+ # @return [Hash] new flipped hash
832
+ # @see http://www.php.net/array_flip
833
+ # @since 2.0.1
834
+ #
835
+ if not self.__hash_utils_instance_respond_to? :flip
836
+ def flip
837
+ self.map_pairs { |k, v| [v, k] }
838
+ end
839
+ end
840
+
841
+ ##
842
+ # Flips keys and values and replaces the original hash in place.
843
+ #
844
+ # @return [Hash] new flipped hash
845
+ # @see http://www.php.net/array_flip
846
+ # @since 2.0.1
847
+ #
848
+ if not self.__hash_utils_instance_respond_to? :flip!
849
+ def flip!
850
+ self.map_pairs! { |k, v| [v, k] }
851
+ end
852
+ end
853
+
828
854
  end
@@ -301,6 +301,19 @@ class Object
301
301
  self.kind_of? Hash
302
302
  end
303
303
  end
304
+
305
+ ##
306
+ # Indicates, object is implementing +Enumerable+.
307
+ #
308
+ # @return [Boolean] +true+ if yes, +false+ in otherwise
309
+ # @since 2.0.1
310
+ #
311
+
312
+ if not __hash_utils_object_respond_to? :enumerable?
313
+ def enumerable?
314
+ self.kind_of? Enumerable
315
+ end
316
+ end
304
317
 
305
318
  ##
306
319
  # Converts object to +Symbol+. In fact, converts it to +String+
data/test CHANGED
@@ -150,6 +150,16 @@ context "Hash" do
150
150
  t.compact!
151
151
  t == { :a => 1 }
152
152
  end
153
+ asserts("#flip") do
154
+ t = { :a => 1, :b => 2, :c => 2 }
155
+ result = t.flip
156
+ result == { 1 => :a, 2 => :c }
157
+ end
158
+ asserts("#flip!") do
159
+ t = { :a => 1, :b => 2, :c => 2 }
160
+ t.flip!
161
+ t == { 1 => :a, 2 => :c }
162
+ end
153
163
  asserts("#get_pairs") do
154
164
  h = { :a => 1, :b => 2, :c => 3 }
155
165
  result = [ ]
@@ -281,6 +291,9 @@ context "Object" do
281
291
  asserts("#boolean?") do
282
292
  true.boolean? and false.boolean? and not "".boolean?
283
293
  end
294
+ asserts("#enumerable?") do
295
+ [].enumerable? and not 5.enumerable?
296
+ end
284
297
  asserts("#false?") do
285
298
  (false.false? == true) and ("string".false? == false)
286
299
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-15 00:00:00.000000000 Z
12
+ date: 2012-08-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-version
16
- requirement: &22439060 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *22439060
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: bundler
27
- requirement: &22434460 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 1.0.0
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *22434460
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: jeweler2
38
- requirement: &22431720 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 2.0.0
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *22431720
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.0
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: riot
49
- requirement: &22448700 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,7 +69,12 @@ dependencies:
54
69
  version: 0.12.3
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *22448700
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.12.3
58
78
  description:
59
79
  email: martinkozak@martinkozak.net
60
80
  executables: []
@@ -92,10 +112,7 @@ files:
92
112
  homepage: http://github.com/martinkozak/hash-utils
93
113
  licenses:
94
114
  - MIT
95
- post_install_message: ! "\nHASH UTILS: The 2.0 version avoids the method overwriting
96
- conflicts by not performing overwriting of already implemented methods. By this
97
- way, it can damage your existing applications based on older versions although it's
98
- very improbable. \n\n"
115
+ post_install_message:
99
116
  rdoc_options: []
100
117
  require_paths:
101
118
  - lib
@@ -107,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
124
  version: '0'
108
125
  segments:
109
126
  - 0
110
- hash: -641600196593062307
127
+ hash: -4026465352187069690
111
128
  required_rubygems_version: !ruby/object:Gem::Requirement
112
129
  none: false
113
130
  requirements:
@@ -116,10 +133,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
133
  version: '0'
117
134
  requirements: []
118
135
  rubyforge_project:
119
- rubygems_version: 1.8.17
136
+ rubygems_version: 1.8.24
120
137
  signing_key:
121
138
  specification_version: 3
122
- summary: Adds more than 125 useful and frequently rather fundamental methods which
139
+ summary: Adds more than 135 useful and frequently rather fundamental methods which
123
140
  are missing in Ruby programming language, to Array, File, Hash, Module, Object,
124
141
  String and Symbol classes. It tries to be similar project to Ruby Facets on principle,
125
142
  but less complex, more practical, non-atomic and organized by better way. Thanks