From: Robert Klemme Date: 2011-08-04T22:31:30+09:00 Subject: Re: Abstract, modules and inheritance question Piter Fcbk wrote in post #1014749: > I have to import some csv files into the database. Each file had a > corresponding model and table in the system. > So I was thinking that there will be some common methods for all the > importers (log, spent_time_in_miliseconds, run, ...) and some non common > methods (convert_line_to_parameters, ...). Some common methods will end > up > calling particular methods (i.e. run will call > convert_line_to_parameters > for each line in the csv file). > > I'm new to Ruby so the first idea that I got in mind was using one > abstract > class and the create one class for each model that has to be imported. > Then I realize that didn't look like a Ruby way to solve this problem. Why that? > My > second thought was to create a module with all the common methods and > include that module in the different importers, but not sure its the > best way either. I think both approaches are perfectly legal and OK. It looks as if the only differing behavior might be to translate a CSV record to fields for DB insertion. So maybe you can get away with a single class which takes a block on construction which is later called to convert each record. You can even read the arity of the block to determine how many placeholders your prepared insert statement needs (if you use some DB API with SQL directly). Kind regards robert -- Posted via http://www.ruby-forum.com/.