小编dmf*_*ari的帖子

Ruby - 在变量中存储列表数据的最佳方法

我是Ruby的新手.我有这样的数据:

year | month |  foo 
--------------------
2016 |     2 |   4 
--------------------
2016 |     3 |  14 
--------------------
 ... |  ...  | ... 
--------------------
2017 |    12 |   9 
Run Code Online (Sandbox Code Playgroud)

我想将该表存储在变量中,并且仍然能够使用年和月列的值访问列foo中的数据.就像是:

data['2016']['2']
Run Code Online (Sandbox Code Playgroud)

得到'4'.

有没有办法做到这一点?

ruby hash

1
推荐指数
1
解决办法
46
查看次数

标签 统计

hash ×1

ruby ×1