mardi 5 mai 2015

Multidimensional Arrays in Ruby like C++

I had previously created a struct and an array of the same in C++ , now i want to implement the same in Ruby.

/ Number of Elements (Which can be increased) :D
#define ELM_NO 110

struct elem
{
  char name[18];
  char elm_symbol[5];

  double atm_weight;

  int elm_melting;
  int elm_boiling;
  int elm_yearofdis;
  int elm_group;

  double elm_ionis_e;
};

elem element[ELM_NO] = { {" Hydrogen"  ,"H"  ,1.0079 ,-259 ,-253 ,1776 ,1  ,13.5984 },
                      {" Hydrogen"  ,"H"  ,1.0079 ,-259 ,-253 ,1776 ,1  ,13.5984  } ,
                      {" Helium"  ,"He" ,4.0026 ,-272 ,-269 ,1895 ,18 ,24.5874  } ,
                      {" Lithium" ,"Li" ,6.941  ,180  ,1347 ,1817 ,1  ,5.3917 } ,
                      {" Beryllium" ,"Be" ,9.0122 ,1278 ,2970 ,1797 ,2  ,9.3227 } ,
                      {" Boron" ,"B"  ,10.811 ,2300 ,2550 ,1808 ,13 ,8.298  } ,
                      {" Carbon"  ,"C"  ,12.0107  ,3500 ,4827 ,0  ,14 ,11.2603  } ,
                      {" Nitrogen" ,"N"  ,14.0067  ,-210 ,-196 ,1772 ,15 ,14.5341  } ,
                      {" Oxygen" ,"O"  ,15.9994  ,-218 ,-183 ,1774 ,16 ,13.6181  } ,
                      {" Fluorine" ,"F"  ,18.9984  ,-220 ,188  ,1886 ,17 ,17.4228  } ,
                      {" Neon" ,"Ne" ,20.1797  ,-249 ,-246 ,1898 ,18 ,21.5645  } ,
                      {" Sodium" ,"Na" ,22.9897  ,98 ,883  ,1807 ,1  ,5.1391 } ,
                      {" Magnesium"  ,"Mg" ,24.305 ,639  ,1090 ,1755 ,2  ,7.6462 } ,
                      {" Aluminum" ,"Al" ,26.9815  ,660  ,2467 ,1825 ,13 ,5.9858 } };

Omitted some parts.

Now , I want to implement in Ruby . The problem is I don't know how to implement 2D arrays from which we can access an Individual Element from the Inner Array.

I have checked on previous Questions , and found that the answers were not either clear or were concerned with Narrays.

Can anybody show me how it's done ?

Aucun commentaire:

Enregistrer un commentaire