From: nobu.nokada@... Date: 2002-04-14T22:55:14+09:00 Subject: Re: RCR: key value mapping for sprintf/% Hi, At Sun, 14 Apr 2002 19:01:56 +0900, Guy N. Hurst wrote: > In Ruby, we have format strings, but they only accept a fixed > number of arguments, and are substituted in the order they are provided. > > "This is first: %s, and this is 2nd: %s" % ['one','two'] Not only in the order. p "This is second: %2$s, and this is 1st: %1$s" % %w[one two] => "This is second: two, and this is 1st: one" > But python allows something like this for the format string: > > ftext = "%(name)s is %(gender)s. %(name)s is %(age)2d years old" While ago I made this patch, using Symbols as keys of the hash. You can find it in [ruby-dev:16351], but it's rejected. ftext = "%(name)s is %(gender)s. %(name)s is %(age)2d years old" hash = {:gender=>"male", :name=>"Fred", :age=>23} ftext % hash # "Fred is male. Fred is 23 years old" -- Nobu Nakada