@ruts said:
...when you call the method euler_angle you create an empty array under variable xyz as parameter.
The secret is that Ruby does not really "have" variables, even though the books use that name. Ruby has references that point at objects, and a reference can be made to point at any class of object, and then later be re-assigned to point at any other object of any class, at any time.
This is referred to as "weakly typed", but really Ruby references are not type locked at all.
@ruts said:
Then nothing happens with the array for the whole piece of code.
Because it (the argument) is just being used as a switch to tell the method what the coder wants as an output. An empty array object is simply the default, which tells the method the calling code expects an array as a return object.
@ruts said:
At the end the array can be ==0 (contains one element which is equal to zero), ==1, ==2 or still empty. How can it be that the array can contain elements?
It cannot. You mis-understand. The method is not testing an array, it is testing a reference to the method argument to see if is pointing at integers 0 or 1 or 2, or still pointing at [] (the default empty array object,) and then returning either the indicated values, or an array of all three.
IF you call the method with no arguments, or like euler_angle([]) you will get an array of 3 values.
IF you call the method thus: euler_angle(0) you will get the x value returned.
IF you call the method thus: euler_angle(1) you will get the y value returned.
IF you call the method thus: euler_angle(2) you will get the z value returned.
The 0, 1 and 2 subscripts come from the SketchUp API's extension of the Array class, where 3 element arrays can act like points and vectors.
Still have not read the book, I see.