Access Ruby Hash Using Dotted Path Key String

后端 未结 7 2247
情深已故
情深已故 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:21

    There is also HashDot.

    HashDot allows dot notation syntax use on hashes. It is faster, and more traversable than an object created with OpenStruct.

    a = {b: {c: {d: 1}}}
    a.b.c.d => 1
    

提交回复
热议问题