ruby - How to populate an array using gets.chomp -


Here's what I've done so far:

  # using an array heading Table of Contents = "Consent Letter" # Chapter Chapter Chapter Chapter = Array.new "Please input chapter names". While gets.chomp! = "" Chapter = gets.chomp chapters. The chapter breaks if it gets broken. Chomp.empty? End # borders puts the pengement = array.Nue in related page numbers "Please input related page numbers" while getting.chomp! = "" Pagenum = gets.chomp pagenumbers.push pagenum becomes broke if it gets. Chomp.empty? Lastly, the chapter puts the page number  

I am trying to get gets.chomp to continue adding to each array. When I suppress chapters or pagenum , I get only the final string / integer input I chapter or PageName Array

The problem here is that every time you enter If you type , then you're calling the becomes method, which brings a line of input from them. You need to store that line somewhere, so it can be used later to try something like this:

  chapter = [] while true input = gets.chomp Break if input.empty? Chapters & lt; & Lt; The input end puts "chapters:" + chapter.joint (",")  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -