How can I get JavaScript style hash access?

后端 未结 4 1785
余生分开走
余生分开走 2021-02-19 11:05

I am aware of this feature provided by ActiveSupport.

h = ActiveSupport::OrderedOptions.new
h.boy = \'John\'
h.girl = \'Mary\'
h.boy  # => \'John\'
h.girl # =         


        
4条回答
  •  星月不相逢
    2021-02-19 11:33

    You are looking for OpenStruct

    $ require 'ostruct'
    $ large_hash_obj = OpenStruct.new large_hash
    $ large_hash_obj.boy
    => "John"
    

提交回复
热议问题