Access Ruby Hash Using Dotted Path Key String

后端 未结 7 2235
情深已故
情深已故 2021-01-01 21:35

The Rails I18n library transforms a YAML file into a data structure that is accessible via a dotted path call using the t() function.

t(\'one.two.three.four\         


        
7条回答
  •  情歌与酒
    2021-01-01 22:18

    I would suggest taking a look at this gist:
    https://gist.github.com/potatosalad/760726

    It adds implode and explode methods to Hash object that transforms nested keys to single-level dotted path keys, and vice versa.

提交回复
热议问题