Converting string output to array

I have to convert the output in the below format to array , how can this be achieved in ruby

Output:
10.1.1.1
10.1.1.2
10.1.1.3

To:
array = [“10.1.1.1”,“10.1.1.2”,“10.1.1.3”]

a = "10.1.1.1
10.1.1.2
10.1.1.3"

array = a.split("\n")
p array     # => ["10.1.1.1", "10.1.1.2", "10.1.1.3"]

If the output is stored in a file output.txt:

b_array = File.readlines("output.txt").map{ |i| i.chomp }
p b_array   #  => ["10.1.1.1", "10.1.1.2", "10.1.1.3"]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs