Forum: Ruby-core [ruby-trunk - Feature #8688][Open] #sprintf should accept strings as keys

85991f138ede6236f35eb98da22b7b01?d=identicon&s=25 Marvin Gülker (quintus)
on 2013-07-25 19:33
(Received via mailing list)
Issue #8688 has been reported by Quintus (Marvin Gülker).

Feature #8688: #sprintf should accept strings as keys

Author: Quintus (Marvin Gülker)
Status: Open
Priority: Normal
Target version:

Hi there,

Kernel#sprintf should support strings as keys. Currently it only works
with symbols:

 {irb(main):001:0> str = "This is %{foo}."
 => "This is %{foo}."
 irb(main):002:0> sprintf(str, :foo => "bar")
 => "This is bar."
 irb(main):003:0> sprintf(str, "foo" => "bar")
 KeyError: key{foo} not found
  from (irb):3:in `sprintf'
  from (irb):3
  from /opt/rubies/mri/bin/irb:12:in `<main>'}

ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

If I want a user to be able to enter format strings and (later) the
corresponding parameter values, I don’t want to call #to_sym on the keys
(because generating symbols from user input is known to cause memory


This topic is locked and can not be replied to.