Ruby newbie: undefined method `with_indifferent_access'

后端 未结 2 698
长情又很酷
长情又很酷 2021-02-19 18:39

I am a new Ruby programmer, and a co-worker of mine to help me get started wrote the following code which ran fine in his environment. However, when I try to run it in my own e

相关标签:
2条回答
  • 2021-02-19 19:13

    Try using:

    require 'active_support/core_ext/hash'
    

    Thats what actually adds the with_indifferent_access method to the normal Hash class.

    0 讨论(0)
  • 2021-02-19 19:13

    By the way, HashWithIndifferentAccess is really powerful as long as you use it with caution.

    For example:

    h = HashWithIndifferentAccess.new()
    some_array.each do |a|
      h["#{a}"] = "anything you want"
    end
    

    I use it all the time when working with slices of data in metrics.

    0 讨论(0)
提交回复
热议问题