Skip to content

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

Description

@michaeledgar

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions