jeudi 21 mai 2015

extract `.for()` into a method

I have a class like this one:

class House

   def bricks
      Brick.for(@house_plan).where(size: 5)
   end

   def wood
       Wood.for(@house_plan).where(size: 5)
   end
end

My goal is to extract the call for(self).where(size: 5):

What I tried first was:

  class House

   def bricks
      Brick.match_material
   end

   def wood
       Wood.match_material
   end

   def match_material
       for(@house_plan).where(size: 5)
   end

end

But then I got this error:

syntax error, unexpected '\n', expecting :: or '[' or '.'

Then I changed my code to:

   def match_material
       .for(@house_plan).where(size: 5)
   end

And now when I do:

 house = House.new(HousePlan.new)
 house.bricks

I get this error:

formal argument cannot be an instance variable

In this line: for(@house_plan).where(size: 5)

What do I wrong?

Aucun commentaire:

Enregistrer un commentaire