File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,6 +90,9 @@ Changes:
9090 * Add ` Dir.find ` as convenience wrapper around Ruby's ` Find.find ` .
9191 * Deprecate ` Dir.recurse ` / ` Dir.ls_r ` (use ` Dir.find ` or ` Find.find ` instead).
9292 * Deprecate ` Proc#compose ` and ` Proc#* ` (use ` Proc#<< ` for right-to-left composition, Ruby 2.6+).
93+ * Deprecate ` Hash#update_keys ` (use ` Hash#transform_keys! ` or ` Hash#rekey! ` ).
94+ * Deprecate ` Hash#update_values ` (use ` Hash#transform_values! ` or ` Hash#revalue! ` ).
95+ * Deprecate ` Hash#fetch_nested ` (use ` Hash#dig ` , adopted by Ruby in 2.3).
9396 * Fix dead requires for removed ` kernel/singleton_class ` in Proc and Kernel.
9497 * Remove misplaced ` applique/file_helpers ` from core (test infrastructure).
9598 * Drop unused ` test_files ` directive from gemspec. (PR #301 )
Original file line number Diff line number Diff line change 11class Hash
22
3- # Similar to Hash#fetch but supports nested lookup and is `nil` safe .
3+ # @deprecated Use Hash#dig instead (built-in since Ruby 2.3) .
44 #
5- # {}.fetch_nested('anything','at','all') #=> nil
5+ # Similar to Hash#dig but supports a block for missing keys,
6+ # like Hash#fetch does. Ruby's #dig does not support a block.
67 #
7- # h = {'hello'=>{'world'=>42}}
8- # h.fetch_nested(*['hello','world']) #=> 42
8+ # TODO: Consider proposing block support for Hash#dig to Ruby core.
99 #
10- # CREDIT: T. Yamada and Sean Mackesey
11-
12- def fetch_nested ( *keys )
10+ def fetch_nested ( *keys , &block )
11+ warn "Hash#fetch_nested is deprecated. Use Hash#dig instead." , uplevel : 1
1312 begin
14- keys . reduce ( self ) { |accum , k | accum . fetch ( k ) }
15- rescue ( RUBY_VERSION < '1.9' ? IndexError : KeyError )
13+ keys . reduce ( self ) { |accum , k | accum . fetch ( k ) }
14+ rescue KeyError
1615 block_given? ? yield ( *keys ) : nil
1716 end
1817 end
Original file line number Diff line number Diff line change 11class Hash
22
3- # Iterate over hash updating just the keys .
3+ # @deprecated Use Hash#transform_keys! (Ruby 2.5+) or Hash#rekey! instead .
44 #
5- # h = {:a=>1, :b=>2}
6- # h.update_keys{ |k| "#{k}!" }
7- # h #=> { "a!"=>1, "b!"=>2 }
8- #
9- # @author Trans
10- # @author Evgeniy Dolzhenko (bug fix)
11-
12- def update_keys #:yield:
5+ def update_keys ( &block )
6+ warn "Hash#update_keys is deprecated. Use Hash#transform_keys! or Hash#rekey! instead." , uplevel : 1
137 if block_given?
14- keys . each { | old_key | store ( yield ( old_key ) , delete ( old_key ) ) }
8+ transform_keys! ( & block )
159 else
1610 to_enum ( :update_keys )
1711 end
1812 end
1913
2014end
21-
Original file line number Diff line number Diff line change 11class Hash
22
3- # Iterate over hash updating just the values .
3+ # @deprecated Use Hash#transform_values! (Ruby 2.4+) or Hash#revalue! instead .
44 #
5- # h = {:a=>1, :b=>2}
6- # h.update_values{ |v| v + 1 }
7- # h #=> { :a=>2, :b=>3 }
8- #
9- # CREDIT: Trans
10-
11- def update_values #:yield:
5+ def update_values ( &block )
6+ warn "Hash#update_values is deprecated. Use Hash#transform_values! or Hash#revalue! instead." , uplevel : 1
127 if block_given?
13- each { | k , v | store ( k , yield ( v ) ) }
8+ transform_values! ( & block )
149 else
1510 to_enum ( :update_values )
1611 end
1712 end
1813
1914end
20-
You can’t perform that action at this time.
0 commit comments