> On Wed, Oct 7, 2009 at 11:11 AM, Joshua Muheim > <[email protected]> wrote: >> class Page < ActiveRecord::Base >> def caption >> caption ? caption : title >> end >> end > > This will produce an infinite loop. I think you want something more > like > > self.caption ? self.caption : self.title > > But honestly I'd rename the method to something else for clarity.
Agreed. At some point you're going to want to access 'caption' directly and the above won't let you do that. Plus your team might not realize you're adding magic. I've always gone with "preferred"... that is.. def preferred_caption # code to get me the ideal caption for the fields available end That helps remind me that I'm not necessarily getting back the caption itself, but the ideal caption for the given situation. It's worked well for me so far. -philip --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

