utilities 0.0.11 → 0.0.12
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.
- data/lib/utilities.rb +14 -2
- data/lib/version.rb +1 -1
- metadata +2 -2
data/lib/utilities.rb
CHANGED
@@ -280,9 +280,21 @@ module Utilities
|
|
280
280
|
end
|
281
281
|
|
282
282
|
class Hash
|
283
|
-
# Returns a new hash
|
283
|
+
# Returns a new hash with the results of running block once for every key in self
|
284
|
+
def collect_keys
|
285
|
+
each_with_object({}){ |(k,v),h| h[yield(k)] = v } if block_given?
|
286
|
+
end
|
287
|
+
alias_method :map_keys, :collect_keys
|
288
|
+
|
289
|
+
# Returns a new hash with the results of running block once for every value in self
|
290
|
+
def collect_values
|
291
|
+
each_with_object({}){ |(k,v),h| h[k] = yield(v) } if block_given?
|
292
|
+
end
|
293
|
+
alias_method :map_values, :collect_values
|
294
|
+
|
295
|
+
# Returns a new hash where all keys have been symbolized
|
284
296
|
def symbolize_keys
|
285
|
-
|
297
|
+
collect_keys{ |k| k.to_sym }
|
286
298
|
end
|
287
299
|
end
|
288
300
|
|
data/lib/version.rb
CHANGED