Clarification for Message Arguments + Splat (III.A.1 - splatting) #126

Open
michaeledgar opened this Issue Feb 6, 2011 · 0 comments

Comments

Projects
None yet
1 participant

The section on applying the splat operator in an argument list misses one important point. It says:

This technique works by sending :to_a to the prefixed object, so any object that responds to this message with an Array can be used in the same fashion.

However, it is important to note that splatting any object will work: if the prefixed object doesn't respond to #to_a, it is wrapped into a one-element array and then splatted, making the splat a no-op. The code for the splatarray bytecode in 1.9 is as follows:

VALUE tmp = rb_check_convert_type(ary, T_ARRAY, "Array", "to_a");
if (NIL_P(tmp)) {
tmp = rb_ary_new3(1, ary);
}
obj = tmp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment