ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What the difference between Hashes and arrays on RUBY ?

user-image
تم إضافة السؤال من قبل Adel Ezat Fawzy Ellozy , Webdeveloper. , Saudi Arabian Maritiem Sports Federation
تاريخ النشر: 2017/03/09
Mohammad Shahbaz Alam
من قبل 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'

المزيد من الأسئلة المماثلة