Dino Dex First Refactor

Let me know when you have a few minutes.  I want to go over a few of the questions you had which I haven't yet done anything with.
I had it as attr_reader before, and someone else (maybe Joe?) recommended I
move it to an accessor and override because attr_reader makes it seems like
a read-only attribute.  Thoughts?

*Jeremy Finzel*

*Senior Database Developer*
*M* 630-777-4520




On Thu, Dec 18, 2014 at 3:15 PM, Dan Kotowski <notifications@github.com>
wrote:
>
> In dino_catalog/dinosaur.rb
> <https://github.com/jmmastey/level_up_exercises/pull/353#discussion-diff-22071774>
> :
>
> > +  attr_accessor :name, :period, :continent, :diet, :walking, :description, :weight_in_lbs
> > +  CARNIVORES = %w(Carnivore Insectivore Piscivore)
> > +  PERIOD_PERIOD_TYPES =
> > +  { "Early Cretaceous" => "Cretaceous",
> > +    "Late Cretaceous" => "Cretaceous",
> > +    "Cretaceous" => "Cretaceous",
> > +    "Jurassic" => "Jurassic",
> > +    "Oxfordian" => "Oxfordian" }
> > +
> > +  def initialize(attributes = {})
> > +    attributes.each { |key, value| send("#{key}=", value) }
> > +  end
> > +
> > +  def weight_in_lbs=(weight_in_lbs)
> > +    @weight_in_lbs = weight_in_lbs.to_i
> > +  end
>
> Actually, this method is overriding the setter from the attr_accessor. If
> you wrote
> def weight_in_lbs=(weight_in_lbs)
> weight_in_lbs = weight_in_lbs
> end
> you would have an infinite loop.
>
> If you want to create a custom setter, make an attr_reader instead of an
> attr_accessor for weight_in_lbs and make the custom accessor there.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/jmmastey/level_up_exercises/pull/353/files#r22071774>.
>