jeudi 25 juin 2015

Generic Module in rails

I have all common function in a module Helper. Those function will work only if it include a constants file which is dynamic based on every project. Now, what is the best approach to reuse the module?

module Helper
  #dunno how to include the constants file and reuse it
  def morning_food(who)
   puts FOOD_HABIT[:morning]
  end
end

../Constant files

module Animal
 module Constants
 FOOD_HABIT = {
  morning: "a",
  ...
 }
 end
end

module Person
 module Constants
 FOOD_HABIT = {
  morning: "dosa",
  ...
 }
 end
end

Aucun commentaire:

Enregistrer un commentaire