Project

General

Profile

Bug #3829 ยป sprintf_hash.patch

View differences:

string.c (working copy)
1224 1224
 *
1225 1225
 *  Format---Uses <i>str</i> as a format specification, and returns the result
1226 1226
 *  of applying it to <i>arg</i>. If the format specification contains more than
1227
 *  one substitution, then <i>arg</i> must be an <code>Array</code> containing
1228
 *  the values to be substituted. See <code>Kernel::sprintf</code> for details
1229
 *  of the format string.
1227
 *  one substitution, then <i>arg</i> must be an <code>Array</code> or <code>Hash</code>
1228
 *  containing the values to be substituted. See <code>Kernel::sprintf</code> for 
1229
 *  details of the format string.
1230 1230
 *
1231
 *     "%05d" % 123                              #=> "00123"
1232
 *     "%-5s: %08x" % [ "ID", self.object_id ]   #=> "ID   : 200e14d6"
1231
 *     "%05d" % 123                             #=> "00123"
1232
 *     "%-5s: %08x" % [ "ID", self.object_id ]  #=> "ID   : 200e14d6"
1233
 *     "foo = %{foo}" % { :foo => 'bar' }       #=> "foo = bar"
1233 1234
 */
1234

  
1235 1235
static VALUE
1236 1236
rb_str_format_m(VALUE str, VALUE arg)
1237 1237
{
sprintf.c (working copy)
422 422
 *     sprintf("%u", -123)                        #=> "-123"
423 423
 *
424 424
 *  For more complex formatting, Ruby supports a reference by name.
425
 *  %<name>s style uses format style, but ${name} style doesn't.
425
 *  %<name>s style uses format style, but %{name} style doesn't.
426 426
 *
427 427
 *  Exapmles:
428 428
 *    sprintf("%<foo>d : %<bar>f" % { :foo => 1, :bar => 2 })
429 429
 *      #=> 1 : 2.000000
430
 *    sprintf("%d %{foo}" % { :foo => 'bar' })
431
 *      # => "%d bar"
430
 *    sprintf("%{foo}f" % { :foo => 1 })
431
 *      # => "1f"
432 432
 */
433 433

  
434 434
VALUE