* Ben Hoskings <[email protected]> [2011-08-18 15:35:11 +1000]: > I'd just like to add, although I agree with all this advice, if you're using > const_get I'd say there's more than a 50% chance that you'd be better off > designing your code in a way that doesn't need it. > > Metaprogramming is sometimes the right tool for the job, but: > > - it usually isn't, > - it's rarely easily maintainable/testable, and most importantly, > - it usually violates the principle of least surprise.
Template Method pattern - it's the easiest way to instantiate the correct class: > def self.create( application, dryrun, logger ) > class_name = application.capitalize + "Snapshot" > the_class = NDM.const_get(class_name) > return the_class.new( application, dryrun, logger ) > end -- Sonia Hamilton http://soniahamilton.wordpress.com http://www.linkedin.com/in/soniahamilton -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
