Ruby 中的关联数组

编程入门 行业动态 更新时间:2024-10-28 16:16:55
本文介绍了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 中的关联数组

本文发布于:2023-10-28 22:39:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537978.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   Ruby

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!