feezy26 feezy26 - 1 year ago 81
Ruby Question

How do I center all of my puts statements in a program without applying the center method to each string?

So I have this code:

puts "hey".center(150)
puts "yo".center(150)
puts "sup".center(150)

How do I make this shorter and more concise? I was thinking of editing the original puts method?

Answer Source

You can just define a method like this:

def my_puts(str)
  puts str.center(150)

And use it like:

my_puts "hey"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download