Ruby : Associative Arrays

前端 未结 3 858
难免孤独
难免孤独 2020-12-13 23:57

Does Ruby on rails have associative arrays?

For eg:

   a = Array.new
   a[\"Peter\"] = 32
   a[\"Quagmire\"] = \'asdas\'

What is

3条回答
  •  囚心锁ツ
    2020-12-14 00:10

    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

    In your case it'd be:

    a = {'Peter' => 32, 'Quagmire' => 'asdas'}
    

    There are several freely available introductory books on ruby and online simulators etc.

    http://www.ruby-doc.org/

提交回复
热议问题