I am very new to Ruby and trying to read each line of a file. I want to create an object called LineAnalyzer using each line and then add that object to an array called analyzers.
The code I am trying is
Class Solution
attr_reader :analyzers;
def initialize()
@analyzers = Array[];
end
def analyze_file()
count = 0;
f = File.open('test.txt')
#* Create an array of LineAnalyzers for each line in the file
f.each_line { |line| la = LineAnalyzer.new(line, count) }
@analyzers.push la;
count += 1;
end
end
end
Any help or suggestions would be greatly appreciate!!
Array[]is not what you mean.[]is sufficient. Empty argument lists on methods are also omitted by convention, so it's simplyinitialize.