This was part of a larger project and I’ve successfully passed all the test cases, but I’m still having trouble understanding the concept of reading from a text file (line by line), creating a class instance for each read line (done inside a different class), and putting each of those class instances into an array (the array is an instance variable inside of the second class).
class Object attr_accessor :str def initialize(sent) @str = sent end end class Solution attr_accessor :array def initialize @array =  end def make_Array File.open("test.txt").each do | line | @array << Object.new(line.chomp) end print @array end end
My text file (names “test.txt”) is as follows:
This is a really really really cool experiment really
Cute little experiment
Will it work maybe it will work do you think it will it will
Upon running the code, I get this message:
warning: redefining Object#initialize may cause infinite loop
Aren’t I creating unique instances of the class when I read each line of the file, so doesn’t that mean that I can shovel them into the array instance variable? Note: the prompt specified that I should only have these two classes in my solution!