I’m running some tutorial and github ruby programs as I learn. When I run one of the programs in terminal, it asks me to enter some things, one per line. I know this is silly but how do I tell it I’m done entering things in terminal?
puts "Please input a list of stocks, one per line"
LifeCycleReportItem.setup
report = Report.new
tickers = Array.new
STDIN.readlines.each { | ticker |
tickers.push(ticker.chomp)
}
Here’s terminal:
Please input a list of stocks, one per line
GOOG
AAPL
How do I tell it I’m done?
Use Ctrl+DEnter to write an EOF (or Ctrl+ZEnter on Windows).
If this software is meant to be easy/used by humans, though, you might consider saying “or a blank line to stop” and checking for that instead. (It won’t work using
STDIN.readlines.each, though – justgetsinstead:))