[#84867] [Ruby trunk Bug#14357] thread_safe tests suite segfaults — v.ondruch@...

Issue #14357 has been reported by vo.x (Vit Ondruch).

11 messages 2018/01/15

[#84980] [Ruby trunk Feature#13618][Assigned] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid — hsbt@...

Issue #13618 has been updated by hsbt (Hiroshi SHIBATA).

10 messages 2018/01/23
[#85012] Re: [Ruby trunk Feature#13618][Assigned] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid — Eric Wong <normalperson@...> 2018/01/23

hsbt@ruby-lang.org wrote:

[ruby-core:84916] [Ruby trunk Feature#14371] New option "recursive: true" for Hash#transform_keys!

From: tagomoris@...
Date: 2018-01-18 05:59:22 UTC
List: ruby-core #84916
Issue #14371 has been updated by tagomoris (Satoshi TAGOMORI).


> Why prefer `each` over `transform_keys!`?
> And probably you wanted to write `elsif`.

Your points are correct. The ideal pseudo code is here:

```ruby
def transform_keys!(recursive: false, &block)
  # do original transform_keys! here
  values.each do |v|
    if v.respond_to?(:transform_keys!)
      v.transform_keys!(recursive: true, &block)
    elsif v.respond_to?(:each)
      v.each{|i| i.transform_keys!(recursive: true, &block) if i.respond_to?(:transform_keys!) }
    end
  end if recursive
end
```

----------------------------------------
Feature #14371: New option "recursive: true" for Hash#transform_keys!
https://bugs.ruby-lang.org/issues/14371#change-69626

* Author: tagomoris (Satoshi TAGOMORI)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
`Hash#transform_keys!` is available when we want to symbolize hash keys.
But in some/many cases (for example, receiver hash object is nested configuration tree loaded from any files), hash object are
nested object, which has hashes or arrays of hashes as values.
It's super useful if we can transform keys of such nested values.

My proposal is `Hash#transform_keys!(recursive: true, &:to_sym)`. Pseudo code is:

```ruby
def transform_keys!(recursive: false, &block)
  # do original transform_keys! here
  values.each do |v|
    if v.respond_to?(:each)
      v.each{|i| i.transform_keys!(recursive: true, &block) if i.respond_to?(:transform_keys!) }
    else v.respond_to?(:transform_keys!)
      v.transform_keys!(recursive: true, &block)
    end
  end if recursive
end
```

The most major usage example is: `config = MyAwesomeFormat.load(file); config.transform_keys!(recursive: true, &:to_sym)`.




-- 
https://bugs.ruby-lang.org/

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