views:

35

answers:

1

Hello,

I have a feed reader written in Rails (the logic is bit complex as I am scraping some data) and I am trying to generalize the methods. Here is my current structure -

Class Gizmodo

  def update

   update logic

  end

end



Class Wired

  def update

    update logic

  end

end

Now I am thinking of structure like this

Class Story

  def update(feed_name)

    logic for feed - stored somewhere

  end

end

I am thinking of storing the methods in table as string and then use class_eval(string) to generate the code. I believe this is ineffective. What are the other ways of storing code?

P.S -

  • I am using tables, because in future I want to add functionality of adding feeds and their logic.
  • Once a feed is added, the logic will stay permanent. Is there a way of hard coding the methods, like writing the methods to module file?
+1  A: 

Try creating a module inside the "lib" directory. All files in the lib directory are automatically loaded on server startup. Create a module, place your feed logic there, and include the module in the controllers that need it. That's how I do it.

Faisal
I want it to be dynamical. Can I create modules on the fly?
Jagira
@Jagira, of course: `Module.new`
banister