feezy26 feezy26 - 4 months ago 13
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?


You can just define a method like this:

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

And use it like:

my_puts "hey"