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

前端 未结 5 1749
-上瘾入骨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:49

    If you have a hash already, you can do:

    HashWithIndifferentAccess.new({'a' => 12})[:a]
    

提交回复
热议问题