Bug #3829

[doc] String#% and a hash

Added by DanielBovensiepen (Daniel Bovensiepen) over 1 year ago. Updated about 1 year ago.

[ruby-core:32386]
Status:Closed Start date:09/15/2010
Priority:Normal Due date:
Assignee:- % Done:

100%

Category:-
Target version:-
ruby -v:ruby 1.9.3dev (2010-09-15 trunk 29250) [x86_64-darwin10.3.2]

Description

String#% can also be used together with a Hash. The documentation is missing this point. This patch is adding documentation to rb_str_format_m and rb_f_sprintf.

sprintf_hash.patch (1.9 kB) DanielBovensiepen (Daniel Bovensiepen), 09/15/2010 02:23 am

Associated revisions

Revision 29254
Added by nobu (Nobuyoshi Nakada) over 1 year ago

* string.c (rb_str_times): mentioned about Hash argument. a patch from Daniel Bovensiepen at [ruby-core:32386]. * sprintf.c (get_hash): ditto, and fix typo.

History

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
This issue was solved with changeset r29254.
Daniel, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

Updated by nagachika (Tomoyuki Chikanaga) over 1 year ago

In r29254 documentation for snprintf actually uses String#%.

Index: sprintf.c
===================================================================
--- sprintf.c	(revision 29261)
+++ sprintf.c	(working copy)
@@ -427,7 +427,7 @@
  *  Exapmles:
  *    sprintf("%<foo>d : %<bar>f" % { :foo => 1, :bar => 2 })
  *      #=> 1 : 2.000000
- *    sprintf("%{foo}f" % { :foo => 1 })
+ *    sprintf("%{foo}f", { :foo => 1 })
  *      # => "1f"
  */

Updated by DanielBovensiepen (Daniel Bovensiepen) over 1 year ago

Tomoyuki Chikanaga is complelty right! Also the previously existing example had the same issue:

Index: sprintf.c
===================================================================
--- sprintf.c	(revision 29266)
+++ sprintf.c	(working copy)
@@ -425,9 +425,9 @@ get_hash(volatile VALUE *hash, int argc, const VAL
  *  %<name>s style uses format style, but %{name} style doesn't.
  *
  *  Exapmles:
- *    sprintf("%<foo>d : %<bar>f" % { :foo => 1, :bar => 2 })
+ *    sprintf("%<foo>d : %<bar>f", { :foo => 1, :bar => 2 })
  *      #=> 1 : 2.000000
- *    sprintf("%{foo}f" % { :foo => 1 })
+ *    sprintf("%{foo}f", { :foo => 1 })
  *      # => "1f"
  */

Also available in: Atom PDF