Jorge Rodriguez2,615 Points
Don't fully understand; contact.phone_numbers.push(phone)
I'm trying to figure it out the following code:
I know the phone is an object that is being appended to an array of contact(another object), in this case the array is phone_numbers, i'm right?.
But i don't fully understand how?
Ioannis Leontiadis9,828 Points
first of all keep in mind that Ruby arrays are not as rigid as arrays in other languages. They grow automatically when adding elements to them and are a kind of one-size-fits-all data structure.
So, in your code you are accessing contact's: object property phone_numbers which is an array. You could do something like,
myArray = contact.phone_numbers myArray.push(phone)
which will had the same result. In the second line you are appending an element into the array. It can be of any type.
Note: Keep in mind that dot notation in Object-Oriented Programming is used for accessing the properties and methods of an object. The .push() function is actually a method of any array.
Hope that helped!