יום חמישי, 6 ביוני 2013

Declare ruby struct

A Ruby code that's demonstrating creating  a struct.

  1: myTestArray = []
  2: 
  3: myTestArray[0] = 'Mr Peer Zvika 42'
  4: 
  5: myTestArray[1] = 'Mrs Peer Dalit 42'
  6: 
  7: puts myTestArray
  8: 
  9: Persons = Struct.new(:title, :Family, :name, :age)
 10: 
 11: personsArray = []
 12: 
 13: myTestArray.each do |nextOne|
 14:   title, Family, name, age = nextOne.chomp.split(' ')
 15:   
 16:   personsArray << Persons.new(title, Family, name, age)
 17: end
 18: 
 19: puts personsArray
 20: 

אין תגובות:

הוסף רשומת תגובה