From: "David A. Black" Date: 2008-04-29T05:10:47+09:00 Subject: Re: Sprintf: what does mean the percent symbol? Hi -- On Tue, 29 Apr 2008, Toki Toki wrote: > Hi all! > > I'm testing the functionality of sprintf and I know that I can use it in > two way: > > sprintf("%.3f", "1.2345") > => "1.234" > > Or > > "%.3f" % "1.2345" > => "1.234" > > In the second example, what does mean the percent symbol (%) between > "%.3f" and "1.2345"? It means apply format string "%.3f" to string > "1.2345"? What I want to know is, the percent symbol is limited to > sprintf or it has a more general use in ruby? > > I've searched on the ruby pickaxe and several other ruby books but I > haven't found anything on the % alone, obviously there are many use of > that combined with option (array: %w, string: %q,%Q, regexp: %r, ...). You can define a % method, which will then be executed when you use the infix %. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates!