Answer the question
In order to leave comments, you need to log in
How to drive the contents of an external file into an array in ruby?
There is a file with a list of domains
. Is it possible to somehow assign an array of all these domains, separated by commas, to some variable using pure ruby?
This file will also be added to the code, so I need the option to read not from a link from the Internet, but from a finished file that I will place in the same directory as the code
Answer the question
In order to leave comments, you need to log in
Of course you can
require 'open-uri'
require 'csv'
url = 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt'
data = open(url)
CSV.new(data, headers: true).each do |((_, domain))|
puts domain
end
Maybe. And what are the difficulties?
Read the documentation for the each_line method of the File class. Or IO.foreach
.
In a variable list, I hope, there will be no difficulty to bring.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question