What would the ruby equivalent be to this python script? -


print ("{0:5s} {1:7s} {2:9s} {3:6s} {4:25s} {5:s}".format('rank', 'points', 'comments', 'hours', 'sub', 'link'))      ent in results:           print ("{0:5s} {1:7s} {2:9s} {3:6s} {4:25s} {5:s}".format(str(ent[0]), str(ent[1]), str(ent[2]), str(round(ent[3], 2)), str(ent[4]), str(ent[5])))

it printing outputs array rows. how can mirror in ruby?

python:

print ("{0:5s} {1:7s} {2:9s} {3:6s} {4:25s} {5:s}".format('rank', 'points', 'comments', 'hours', 'sub', 'link')) 

ruby:

puts "%-5s %-7s %-9s %-6s %-25s %-5s" % ['rank', 'points', 'comments', 'hours', 'sub', 'link'] 

alternatively:

puts sprintf("%-5s %-7s %-9s %-6s %-25s %-5s", *['rank', 'points', 'comments', 'hours', 'sub', 'link']) 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -