I have a class that reads a dynamic CSV file, and would like to create a struct based on the headers of the CSV.
It goes like this in pseudo-code:
class SomeClass
def initialize(csvfile)
@csv = CSV.open(csvfile, options.....)
.....
headers = @csv.headers # => [:line, :error, :user, ........] <==this is dynamic
RECORD = Struct.new(headers)
load_data
end
def load_data
@records = []
@csv.each do |r|
@records << RECORD.new(r.fields)
end
end
end
The issue is that a constant can not (should not) be dynamically defined. So, what should be the proper way to address this?