From: "Mehr, Assaph (Assaph)" Date: 2004-06-03T11:50:27+09:00 Subject: Re: What is the equivalent of Python's "%s" % "MyString"? > def myformat4(str, hash) > str.gsub( %r{%\((\w+)\)([dsi])?} ) { "%#{$2}" % hash[$1] } > end > Note: I didn't bother to look up all legal formatting characters. This also doesn't take care of complex formats, like "%-6.3f". Could easily be extended though, but since this requires common agreement (do we use "%fmt(var)" or "%(var)fmt" ?), I'd much rather see Nobu's RCR come into being. Also, I'm surprised no one offered the evil eval: irb(main):001:0> s = '#{name}' => "#{name}" irb(main):002:0> name = "Bob" => "Bob" irb(main):003:0> eval "\"#{s}\"" => "Bob" (Not that it deals with formats in anyway, or that I recommend using it :)