If I have a hash in Ruby on Rails, is there a way to make it indifferent access?

前端 未结 5 1747
-上瘾入骨i
-上瘾入骨i 2021-02-01 12:04

If I already have a hash, can I make it so that

h[:foo]
h[\'foo\']

are the same? (is this called indifferent access?)

The details: I

5条回答
  •  后悔当初
    2021-02-01 12:58

    You can just use with_indifferent_access.

    SETTINGS = YAML.load_file("#{RAILS_ROOT}/config/settings.yml").with_indifferent_access
    

提交回复
热议问题