First Dino Dex Program

I have it set up right now to just run the code in the Main class, and it prints the results to the console.
I'm not sure I understand here because data is all of the rows of
dinosaurs.  If I just do Dinosaur.new, then it creates one dinosaur, which
next time I go around the loop is lost.  I need to store to a local
variable I think, because I am adding an instance of Dinosaur for each row
to create an array of Dinosaurs.  Or am I missing something?

*Jeremy Finzel*

*Senior Database Developer*
*M* 630-777-4520




On Tue, Dec 16, 2014 at 8:21 PM, Joseph Mastey <notifications@github.com>
wrote:
>
> In dino_catalog/dinosaur_import.rb
> <https://github.com/jmmastey/level_up_exercises/pull/350#discussion-diff-21948957>
> :
>
> > +      @data = CSV.read(csv_file, DEFAULT_OPTIONS)
> > +      dinosaurs_from_file = data_to_dinosaurs
> > +      dinosaurs.concat(dinosaurs_from_file)
> > +    end
> > +    @dinosaurs = dinosaurs
> > +  end
> > +
> > +  def data_to_dinosaurs
> > +    dinosaurs = []
> > +    @data.each do |row|
> > +      hash = row.to_hash
> > +      hash = self.class.convert_import_hash(hash)
> > +      dinosaurs << Dinosaur.new(hash)
> > +    end
> > +    dinosaurs
> > +  end
>
> Too many sets of local dinosaurs vars. @data.map would accomplish the
> same in this case:
>
> data.map do |row|
>   hash = self.class.convert_import_hash(row.to_hash)
>   Dinosaur.new(hash)
> end
>
> Any time you can avoid setting a local, try to do that. Less to have to
> reason about. Ditto class vars. Just pass it into the method.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/jmmastey/level_up_exercises/pull/350/files#r21948957>.
>