[ruby-core:82066] Re: [ruby-cvs:66506] mrkn:r59328 (trunk): hash.c: Add Hash#transform_keys and Hash#transform_keys!

From: Kazuki Yamaguchi <k@...>
Date: 2017-07-14 10:25:45 UTC
List: ruby-core #82066
On Fri, Jul 14, 2017 at 03:44:00PM +0900, mrkn@ruby-lang.org wrote:
> mrkn	2017-07-14 15:44:00 +0900 (Fri, 14 Jul 2017)
> 
>   New Revision: 59328
> 
>   https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59328
> 
>   Log:
>     hash.c: Add Hash#transform_keys and Hash#transform_keys!
>     
>     * hash.c (transform_keys_i, rb_hash_transform_keys): Add Hash#transform_keys.
>       [Feature #13583] [ruby-core:81290]
>     
>     * hash.c (rb_hash_transform_keys_bang): Add Hash#transform_keys!.
>       [Feature #13583] [ruby-core:81290]
>     
>     * test/ruby/test_hash.rb: Add tests for above changes.

Just noticed an edge case where those methods behave differently. Both
behaviors seem reasonable to me, but I think they should be consistent.

	$ ruby -e 'h={1=>:a,2=>:b}; p h.transform_keys{|k|k==1 ? 2 : 1}'
	{2=>:a, 1=>:b}
	$ ruby -e 'h={1=>:a,2=>:b}; p h.transform_keys!{|k|k==1 ? 2 : 1}'
	{1=>:a}

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next