I came across an illustration of this in a text but when I tried it in my IRB shell I get an error. Is this following code legal? OTherwise is there a shorthand way to do get the middle array (say median of 1 or 2 elements assuming a sorted array).
irb(main):004:0> first, *middle, last = [42, 43, 44, 45, 46, 47]
SyntaxError: compile error
(irb):4: syntax error, unexpected ',', expecting '='
first, *middle, last = [42, 43, 44, 45, 46, 47]
^
from (irb):4
from :0
It appears you are using ruby 1.8.7. That syntax requires at least 1.9.2 or so.
I know the system ruby that ships with a lot of systems is still 1.8.7, but it is not supported any more and you really should install ruby 2.x.