Learn to Program
Chapter 6
More About Methods
Mean Mom
This is pretty much the same as in the book. I just added some extras.
#Mean mommy
puts 'You walk into the kitchen, your mother has her back to you.'
puts 'What do you say?'
demand = gets.chomp.upcase
puts 'WADDYA MEAN "' + demand + '"?!? YOU\'RE GROUNDED!'
gets #press enter to exit
Result:
Line Width and Justification
I created a three-column table with only one line of data. I left-justified everything because right-justification seemed a little odd.
I put each line into its own variable and concatenated them just for the purposes of showing it on this web page. I originally had it on one line. Either way is acceptible.
#Line width and justifictaion examples
lineWidth = 66
puts ''
puts ''
title = 'Sample Table'.center(lineWidth)
row1 = 'LAST NAME'.ljust(lineWidth/3)
row1 += 'FIRST NAME'.ljust(lineWidth/3)
row1 += 'ID'.ljust(lineWidth/3)
row2 = 'Hough'.ljust(lineWidth/3)
row2 += 'Jessica'.ljust(lineWidth/3)
row2 += '007'.ljust(lineWidth/3)
puts title
puts row1
puts row2
Result: