sprintf 1.9 should support %{}/%<> style referencing #1627

Closed
y8 opened this Issue Mar 20, 2012 · 1 comment

2 participants

@y8
y8 commented Mar 20, 2012

Kernel#sprintf and String#% should support named references.

From docs:

For more complex formatting, Ruby supports a reference by 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("%{foo}f", { :foo => 1 })
  # => "1f"
@subwindow
Rubinius member

I noticed this a few days ago. I added specs for this feature in 06114ec, and failing tags in 312c05b.

I looked at it for an hour or so and couldn't figure out how to implement it. sprintf is a tough nut to crack. Feel free to give it a shot!

@dbussink dbussink added a commit that closed this issue Mar 19, 2013
@dbussink dbussink Add support for 1.9 named hash arguments in sprintf
We use the same parsing for 1.8 and 1.9 mode, just the regular
expression is different so the new 1.9 style is never matched by the 1.8
regexp. This makes for less duplicate code, while supporting both modes
properly.

Fixes #1627
ae7f85b
@dbussink dbussink closed this in ae7f85b Mar 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment