2009/6/3 Dave L <[email protected]>: > > Okay, thanks a lot. That really helps. For the logged_in_user, that > would be a User instance method, right? Something like: > > Class User < ActiveRecord::Base > def return_instructions_array > instructions = Instructions.return_array(self.appointments) > end > end
It is a matter of taste, but I would probably just call it instructions, and you don't actually need the assignment operation, a method automatically returns the last value determined so I would possibly use def instructions Instructions.appointments(self.appointments) end Then the call reads intuitively @instructions = User.instructions Or maybe better if it were called current_instructions to indicate that it is the current user. I always try and make the code read so that it as clear as possible what is happening without having to use any more comments than necessary. > This would be an Instructions class method...is this better than an > Instruction instance method? like: > > Instructions.new.return_array(self.appointments) There is no point making it an instance method, it just means you have to make an instance in order to call it. Generally if a method is acting on a single instance of a class then it should be an instance method, if it is acting on a set of them then make it a class method. Not that I am a Ruby expert, there may well be a more elegant way of achieving this. Colin > > I'm never really sure which is better. > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

