I have a large class of algorithms (50-100 methods) used in calculating some results for a model class. I have created a separate algorithm.rb file which contains the class. Where should this file go ? Should it even be a module instead of a class (though I do need it to hold class variables during the calculations)? Finally, how do I call it from the model active record class ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
john wrote:> I have a large class of algorithms (50-100 methods) used in calculating > some results for a model class. I have created a separate algorithm.rb > file which contains the class. Where should this file go ?If it doesn''t use ActiveView or ActiveRecord, it goes in the lib/ folder.> Should it > even be a module instead of a class (though I do need it to hold class > variables during the calculations)?We use Modules when we want to isolate the name of a class, and/or when we want the Module to mix-in with other classes. If you don''t need those, then do what''s simplest. Plop a Class into the lib/ folder, and worry about name collisions when they happen. (If you publish this class, however, that formula no longer applies, and you should put the class in a module with a name that others are not likely to use.;)> Finally, how do I call it from the > model active record class ?Given lib/algorithm.rb, write: require ''algorithm'' up at the top of the Model that uses it. And toss your test cases into test/unit . (You do _have_ test cases, don''t you?;) -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you are using your algorithms in places besides your webapp, why not make yourself an algorithms gem and install it on your system? On 1/12/07, john <John.Staff2222-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have a large class of algorithms (50-100 methods) used in calculating > some results for a model class. I have created a separate algorithm.rb > file which contains the class. Where should this file go ? Should it > even be a module instead of a class (though I do need it to hold class > variables during the calculations)? Finally, how do I call it from the > model active record class ? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phlip wrote:> If it doesn''t use ActiveView or ActiveRecord, it goes in the lib/ folder.> Given lib/algorithm.rb, write: > > require ''algorithm''okay> And toss your test cases into test/unit . (You do _have_ test cases, don''t > you?;)How do I set up a test stub for the separate class file. To get code converted to ruby, I had made it a separate controller and yes, have been testing every method. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---