Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What the difference between Hashes and arrays on RUBY ?

user-image
Question added by Adel Ezat Fawzy Ellozy , Webdeveloper. , Saudi Arabian Maritiem Sports Federation
Date Posted: 2017/03/09
Mohammad Shahbaz Alam
by 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

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.