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.
我有一个哈希PAYMENT_TYPES_HASH。有没有办法从这个哈希创建一个数组,each而不用在它之前声明数组a = []?
PAYMENT_TYPES_HASH
each
a = []
a = []; PAYMENT_TYPES_HASH.each {|order| a << [order[:name], order[:id]]} a
像这样的东西:
array = PAYMENT_TYPES_HASH.each {|order| do something to return the array}
你应该使用#map方法:
#map
PAYMENT_TYPES_HASH.map {|order| [order[:name], order[:id]]}