Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What the difference between Hashes and arrays on RUBY ?

user-image
Question ajoutée par Adel Ezat Fawzy Ellozy , Webdeveloper. , Saudi Arabian Maritiem Sports Federation
Date de publication: 2017/03/09
Mohammad Shahbaz Alam
par Mohammad Shahbaz Alam , Software Developer , 3Man Consulting Pvt Ltd

An array is a collection of data.Each element of an array is accessed using an integer which is the index of the element in an array.

Let's create an array, name

name = ["Shahbaz","Ramesh","Pramod"]

Now, if we want to access the elements of an array, we simply do

name[0]

=>will print 'Shahbaz'

 

Hash is the collection of key-value pair.In Hash, the value is accessed using the key.

let's create a hash, my_details

 

my_details = {'name' => 'shahbaz'}

and if, we want to access the value of hash,we simply do

my_details['name']

=>will print 'shahbaz'

More Questions Like This