On Feb 28, 11:51 pm, Nobuyoshi Nakada <n... / ruby-lang.org> wrote: > Hi, > > At Fri, 29 Feb 2008 01:57:23 +0900, > Trans wrote in [ruby-talk:292860]: > > > I have a question and perhaps a bit of challenge for those with mad > > parse skills: Has anyone ever considered named parameters for sprintf/ > > printf? It would be quite useful (to me at least) to be able to do: > > Yes, once I had posted the patch for it, and was rejected. :( > > "I am %(name)s." % { :name => "Tom" ] > > > Has anyone worked on something like this before? Is there anything > > equivalent in the Perl world or other language? I realize we can use > > numerals to identify the substitutions, but I feel the labels are much > > more readable. Moreover, ultimately it would be interesting to see: > > > "I am %(name)s." % binding > > > Making use of the binding's local_variables. > > Though I don't feel it attractive, I believe named parameter is > an important feature for I18N, and IIRC, ruby-gettext has it. Really? It seems like a nice way to apply parameter to templates to me. Rather then, say, xml = %{ <customer id="#{params[:id]}"> <name>#{params[:name]}</name> </customer> } One could do: xml = %{ <customer id="%(id)u"> <name>%(name)s</name> </customer> } % params A little cleaner --and provides a nice means of reusable interpolation. I'll have to look at ruby-gettext. Thanks, T.