/* * call-seq: * str % arg => new_str * * Format---Uses <i>str</i> as a format specification, and returns the result * of applying it to <i>arg</i>. If the format specification contains more than * one substitution, then <i>arg</i> must be an <code>Array</code> containing * the values to be substituted. See <code>Kernel::sprintf</code> for details * of the format string. * * "%05d" % 123 #=> "00123" * "%-5s: %08x" % [ "ID", self.id ] #=> "ID : 200e14d6" */ static VALUE rb_str_format(str, arg) VALUE str, arg; { VALUE *argv; if (TYPE(arg) == T_ARRAY) { argv = ALLOCA_N(VALUE, RARRAY(arg)->len + 1); argv[0] = str; MEMCPY(argv+1, RARRAY(arg)->ptr, VALUE, RARRAY(arg)->len); return rb_f_sprintf(RARRAY(arg)->len+1, argv); } argv = ALLOCA_N(VALUE, 2); argv[0] = str; argv[1] = arg; return rb_f_sprintf(2, argv); }