Issue #10130 has been updated by Tsuyoshi Sawada.


Now that we have `Hash#dig` and `Array#dig` coming for Ruby 2.3, I think that this proposal of mine from the past makes more sense. 

Regarding Matz' point (2), this proposal should parallel the feature of `dig`. It doesn't add extra cognitive load to us beyond what we would know about `dig` in the coming version of Ruby.

Regarding Matz' point (3), string format (`%{}`) cannot be replaced by string interpolation (`#{}`) when we want a static file that is to be used as a template, to which values would be inserted later to output a page. Interpolation requires dynamic evaluation of the string each time.

Regarding Matz' point (1), instead of using the period as the delimiter, we can use a comma (followed by optional space characters), which would resemble how `dig` is called.

    "Author: %{author, name} (%{author, affiliation}), %{date}" % {author: {name: "Ruby Taro", affiliation: "Ruby co."}, date: "2014, 8, 14"}
    #=> "Author: Ruby Taro (Ruby co.), 2014, 8, 14"

This requires a key with a comma inside `%{}` not to be interpreted as a single symbol but as a sequence of symbols separated by the comma (followed by space characters). Since it is rare that a comma is used in a symbol, I don't think it will affect existing code.

----------------------------------------
Feature #10130: String format with nested hash
https://bugs.ruby-lang.org/issues/10130#change-55495

* Author: Tsuyoshi Sawada
* Status: Rejected
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
When we do string format with hashes, we have the restriction that the hash cannot be a nested one. When we want to handle more complicated string formats, for example in templates, it is more convenient if we can use a nested hash.

    "Author: %{author.name} (%{author.affiliation}), %{date}" % {author: {name: "Ruby Taro", affiliation: "Ruby co."}, date: "2014, 8, 14"}
    #=> "Author: Ruby Taro (Ruby co.), 2014, 8, 14"



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