def normalize(property) result = normalize_generic(self.send(property)) self.send("#{property}_min=", result[:min]) self.send("#{property}_max=", result[:max]) self.send("#{property}=", result[:display]) end
object.normalize(:size) object.normalize(:budget) - Maurício Linhares http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr On Thu, Aug 27, 2009 at 10:40 AM, Axinte Logo<al...@evo-green.fr> wrote: > Hello > > I'm trying to DRY my code and I think It could be done even better. The > following 2 functions are "before_save" callbacks that practically do the > same thing, but on a different set of attributes. > > Since the code is highly similar, I was wondering if someone could help me > to refactor the code? > > > def normalize_budget > result = normalize_generic(self.budget) > self.budget_min = result[:min] > self.budget_max = result[:max] > self.budget = result[:display] > end > > def normalize_size > result = normalize_generic(self.size) > self.size_min = result[:min] > self.size_max = result[:max] > self.size = result[:display] > end > > > Kind regards, > Axinte > > > > --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---