Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Comments

@michaeledgar
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant