Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Chapter 8 ##
- ### Building and sorting an array
- puts 'insert item into array: '
- new_item_array = gets.chomp
- my_array = []
- while new_item_array != ''
- my_array.push new_item_array
- puts 'insert item into array: '
- new_item_array = gets.chomp
- end
- puts my_array.sort
- ### Table of contents, revisited
- title = 'Table of Contents'
- contents = [ ['Chapter 1:' , 'Getting Started', 'page 1'],
- ['Chapter 2:', 'Number', 'page 9'],
- ['Chapter 3:', 'Letters', 'page 13']]
- numItems = contents.length
- line_width = 20
- puts title.center(50)
- puts ''
- contents.each do |item|
- puts item[0].ljust(line_width) + item[1].ljust(line_width) + item[2].ljust(line_width)
- end
Add Comment
Please, Sign In to add comment