Tuesday, February 26, 2008

Advanced puts Syntax in Ruby

The "puts" command can be used with sprintf syntax using the percent (%) sign as follows:

puts "ABC %2.2f" % 3.567
=> "ABC 3.57
"

puts "ABC %2.2f DEF %5s" % [3.567, "abcd"]
=>
"ABC 3.57 DEF abcd"



No comments: