Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个数据数组和一个按特定顺序排列的键数组:
original_data = ['hello', 'world', 'one', 'two'] keys = [:greeting, :location, :first, :second]
我想将键映射到数据,以便能够通过这样的键引用每个数据。
data[:greeting].should == original_data[0]
我怎样才能做到这一点?
那将是:
data = Hash[keys.zip original_data]