Project

General

Profile

Bug #3829 ยป sprintf_hash.patch

View differences:

string.c (working copy)
*
* 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.
* one substitution, then <i>arg</i> must be an <code>Array</code> or <code>Hash</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.object_id ] #=> "ID : 200e14d6"
* "%05d" % 123 #=> "00123"
* "%-5s: %08x" % [ "ID", self.object_id ] #=> "ID : 200e14d6"
* "foo = %{foo}" % { :foo => 'bar' } #=> "foo = bar"
*/
static VALUE
rb_str_format_m(VALUE str, VALUE arg)
{
sprintf.c (working copy)
* sprintf("%u", -123) #=> "-123"
*
* For more complex formatting, Ruby supports a reference by name.
* %<name>s style uses format style, but ${name} style doesn't.
* %<name>s style uses format style, but %{name} style doesn't.
*
* Exapmles:
* sprintf("%<foo>d : %<bar>f" % { :foo => 1, :bar => 2 })
* #=> 1 : 2.000000
* sprintf("%d %{foo}" % { :foo => 'bar' })
* # => "%d bar"
* sprintf("%{foo}f" % { :foo => 1 })
* # => "1f"
*/
VALUE
    (1-1/1)