From: Bira Date: 2006-05-07T05:10:05+09:00 Subject: self.new and initialize ( was Re: Creating sub-classes using Struct) On 5/6/06, Logan Capaldo wrote: > I would suggest > > class Database > def self.new(file_containing_info) > fields = parse_field_format(file_containing_info) > Database.const_set('Record", Struct.new(*fields)) > super > end > > def initialize(file) > @records = [] > read_each_record_in_file(file) do |record_data| > record = Database::Record.new > extract_record_data_into(record_data, record) > @records << record > end > end > end I think I still have a long way to go before I can write a decent, Ruby-ish example :). This one is a little beyond my ability to understand at a glance... What happens when I call Database.new(some_file) ? In which order to the "new" and "initialize" methods get called? -- Bira http://compexplicita.blogspot.com http://sinfoniaferida.blogspot.com