Hash with indifferent access

前端 未结 2 797
失恋的感觉
失恋的感觉 2021-02-01 03:14

I have a non-Rails project in which I am loading some settings from a YAML file:

config = YAML::load(File.open(\"#{LOG_ROOT}/config/database.yml\"))
2条回答
  •  无人共我
    2021-02-01 04:06

    You lose nothing except a few kB of disk space by installing the Active Support gem. In your code, you require only the function you want:

    require 'active_support/core_ext/hash/indifferent_access'
    

    That way, you can be sure you are not getting anything else to mess up your namespace.

提交回复
热议问题