本文介绍了Ruby 中的关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Ruby 有关联数组吗?
Does Ruby have associative arrays?
例如:
a = Array.new a["Peter"] = 32 a["Quagmire"] = 'asdas'在 Ruby 中创建这种数据结构的最简单方法是什么?
What is the easiest method to create such an data structure in Ruby?
推荐答案与将数组和散列混为一谈的 PHP 不同,在 Ruby(以及几乎所有其他语言)中,它们是一个独立的东西.
Unlike PHP which conflates arrays and hashes, in Ruby (and practically every other language) they're a separate thing.
ruby-doc/core/classes/Hash.html
你的情况是:
a = {'Peter' => 32, 'Quagmire' => 'asdas'}有几本免费的关于 ruby 和在线模拟器等的介绍性书籍.
There are several freely available introductory books on ruby and online simulators etc.
www.ruby-doc/
更多推荐
Ruby 中的关联数组
发布评论