nobu.nokada / softhome.net wrote: >Hi, > >At Wed, 2 Jun 2004 03:43:42 +0900, >Sam Sungshik Kong wrote in [ruby-talk:102028]: > > >>s = "My name is %(name)s and my age is %(age)d." % {"name": "Sam", "age": 34} >> >> > > > >>I know that ruby has "#{name}" expression. >>But that requires a variable named "name" in advance. >>I want to bind the format string and data later. >> >> > >I proposed that feature once in [ruby-dev:16351], though >rejected, but still I think that it would be useful for I18N. >Is it worth for RCR? > > > That would be a nice feature. And it struck me that perhaps you could use the keen suggestion by Michael Neumann mneumann / ntecs.de to do something like that def myformat(str, hash) hash.each do |k,v| str = str.gsub("%(#{k})", v) end str end # s = '%string is number %digit' #then define its vars h = {'string=> 'ruby','digit'=>1} #parse p myformat(s,h) string manipulation elegance is one of ruby's strengths, i think |there are neat ways to use string#scan and blocks for this too. http://phrogz.net/ProgrammingRuby/lang_index.html#s | :paul