From e15738ea74d3cda70ae22d1e0895e6dccbc7b085 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 20 Jul 2025 06:05:45 +0900 Subject: [PATCH] mruby-sprintf: add comprehensive call-seq documentation for String#% method - %: string formatting operator that uses the string as a format specification and applies it to the given argument(s), supports both single arguments and arrays for multiple substitutions, delegates to sprintf for actual formatting The method now has comprehensive call-seq documentation with practical examples demonstrating various sprintf formatting patterns including: - Zero-padded integers: "%05d" % 123 - Multiple substitutions with arrays: "%-5s: %016x" % [name, id] - Hash-based named substitutions: "foo = %{foo}" % { :foo => 'bar' } - Named format specifiers: "%{foo}f" % { :foo => 1 } Co-authored-by: Atlassian Rovo Dev --- mrbgems/mruby-sprintf/mrblib/string.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mrbgems/mruby-sprintf/mrblib/string.rb b/mrbgems/mruby-sprintf/mrblib/string.rb index d7e55536a..dbd626350 100644 --- a/mrbgems/mruby-sprintf/mrblib/string.rb +++ b/mrbgems/mruby-sprintf/mrblib/string.rb @@ -1,4 +1,19 @@ class String + # + # call-seq: + # str % arg -> new_str + # str % args -> new_str + # + # Format - Uses str as a format specification, and returns the result + # of applying it to arg. If the format specification contains more than + # one substitution, then arg must be an Array or Hash containing the values + # to be substituted. See sprintf for details of the format string. + # + # "%05d" % 123 #=> "00123" + # "%-5s: %016x" % [ "ID", self.object_id ] #=> "ID : 00002b054ec93168" + # "foo = %{foo}" % { :foo => 'bar' } #=> "foo = bar" + # "%{foo}f" % { :foo => 1 } #=> "1f" + # def %(args) if args.is_a? Array sprintf(self, *args)