我正在开发一个 ruby 应用程序,在该应用程序中,我需要连接多个发送方法调用以访问具有键数组的复杂散列。为了使用send方法访问hash的元素,我一直在使用Hashugar gem。例如:
hash = { one: 1, two: 2, more: [{ three: 3}, {four: 4}] }.to_hashugar
keys = ['more', 'first', 'three'] # 'first' is the first elements of the array
hash.send( *keys ) # FAIL
Run Code Online (Sandbox Code Playgroud)
我一直在尝试不同的方法来使它工作,但我做不到。有没有可能实现这一目标?我是否需要删除Hashugar并不重要。
提前致谢。