[DOC] Tweaks for String#%
This commit is contained in:
parent
ce8f7da49e
commit
d71e171464
Notes:
git
2025-05-05 07:20:55 +00:00
20
string.c
20
string.c
@ -2912,20 +2912,22 @@ rb_str_times(VALUE str, VALUE times)
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* string % object -> new_string
|
||||
* self % object -> new_string
|
||||
*
|
||||
* Returns the result of formatting +object+ into the format specification +self+
|
||||
* (see Kernel#sprintf for formatting details):
|
||||
* Returns the result of formatting +object+ into the format specifications
|
||||
* contained in +self+
|
||||
* (see {Format Specifications}[rdoc-ref:format_specifications.rdoc]):
|
||||
*
|
||||
* "%05d" % 123 # => "00123"
|
||||
* '%05d' % 123 # => "00123"
|
||||
*
|
||||
* If +self+ contains multiple substitutions, +object+ must be
|
||||
* an Array or Hash containing the values to be substituted:
|
||||
* If +self+ contains multiple format specifications,
|
||||
* +object+ must be an array or hash containing the objects to be formatted:
|
||||
*
|
||||
* "%-5s: %016x" % [ "ID", self.object_id ] # => "ID : 00002b054ec93168"
|
||||
* "foo = %{foo}" % {foo: 'bar'} # => "foo = bar"
|
||||
* "foo = %{foo}, baz = %{baz}" % {foo: 'bar', baz: 'bat'} # => "foo = bar, baz = bat"
|
||||
* '%-5s: %016x' % [ 'ID', self.object_id ] # => "ID : 00002b054ec93168"
|
||||
* 'foo = %{foo}' % {foo: 'bar'} # => "foo = bar"
|
||||
* 'foo = %{foo}, baz = %{baz}' % {foo: 'bar', baz: 'bat'} # => "foo = bar, baz = bat"
|
||||
*
|
||||
* Related: see {Methods for Converting to New String}[rdoc-ref:String@Methods+for+Converting+to+New+String].
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
Loading…
x
Reference in New Issue
Block a user