On Apr 21, 2007, at 5:40 PM, shawn bright wrote:
puts “i have %s foo and %s bar” % don’t know what goes here
i know, quite a beginner question, would appreciate any help
thanks
sk
From ri:
--------------------------------------------------------------- String#%
str % arg => new_str
Format---Uses _str_ as a format specification, and returns the
result of applying it to _arg_. If the format specification
contains more than one substitution, then _arg_ must be an +Array+
containing the values to be substituted. See +Kernel::sprintf+ for
details of the format string.
"%05d" % 123 #=> "00123"
"%-5s: %08x" % [ "ID", self.id ] #=> "ID : 200e14d6"
So, it’d be:
puts “i have %s foo and %s bar” % [foo, bar]