From: Phillip Gawlowski Date: 2011-01-18T21:30:17+09:00 Subject: Re: The most recommended way of naming methods in Ruby On Tue, Jan 18, 2011 at 9:16 AM, Edmond Kachale wrote: > Rubists, > > What is the most recommended (or the conventional) way of naming methods in > Ruby? Do they need to be verb-like or noun-like? In other language like C++, > methods are supposed to be verbs because they are dimmed as messages sent to > the object. I have asked this because methods in Ruby are also objects. Well, I can't speak for Rubyists in general, but I aim for the following: - methods that do something should be verbs: obj.calculate obj.set_name obj.get_date - methods that are accessors (or behave like them) should be nouns: foo = obj.name puts obj.date obj.calculation - Interrogative methods get phrased as questions: obj.date_today? obj.name? obj.calculation_done? - methods that modify the object (or caller) itself, should be exclamations: obj.truncate! obj.remove_name! obj.date! "Julian" # I wish I could do obj.date "Julian"!, instead. Ah, well. -- Phillip Gawlowski Though the folk I have met, (Ah, how soon!) they forget When I've moved on to some other place, There may be one or two, When I've played and passed through, Who'll remember my song or my face.