Guest User

Untitled

a guest
Apr 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. ## Chapter 8 ##
  2.  
  3. ### Building and sorting an array
  4. puts 'insert item into array: '
  5. new_item_array = gets.chomp
  6. my_array = []
  7.  
  8. while new_item_array != ''
  9.  
  10. my_array.push new_item_array
  11. puts 'insert item into array: '
  12. new_item_array = gets.chomp
  13.  
  14. end
  15.  
  16. puts my_array.sort
  17.  
  18. ### Table of contents, revisited
  19.  
  20. title = 'Table of Contents'
  21.  
  22. contents = [ ['Chapter 1:' , 'Getting Started', 'page 1'],
  23. ['Chapter 2:', 'Number', 'page 9'],
  24. ['Chapter 3:', 'Letters', 'page 13']]
  25.  
  26. numItems = contents.length
  27. line_width = 20
  28.  
  29. puts title.center(50)
  30. puts ''
  31.  
  32. contents.each do |item|
  33. puts item[0].ljust(line_width) + item[1].ljust(line_width) + item[2].ljust(line_width)
  34. end
Add Comment
Please, Sign In to add comment