Ruby:关联数组 [英] Ruby : Associative Arrays
本文介绍了Ruby:关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Ruby on Rails是否具有关联数组?
Does Ruby on rails have associative arrays?
例如:
a = Array.new
a["Peter"] = 32
a["Quagmire"] = 'asdas'
在Ruby中创建这种数组结构的最简单方法是什么?
What is the easiest method to create such an array structure in Ruby?
推荐答案
与PHP中的将数组和哈希值变混的PHP不同,在Ruby(以及几乎所有其他语言)中,它们是独立的.
Unlike PHP which conflates arrays and hashes, in Ruby (and practically every other language) they're a separate thing.
http://ruby-doc.org/core/classes/Hash.html
以您的情况为例:
a = {'Peter' => 32, 'Quagmire' => 'asdas'}
关于红宝石和在线模拟器等,有几本免费的入门书籍.
There are several freely available introductory books on ruby and online simulators etc.
这篇关于Ruby:关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文