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.
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.
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.
Not exactly. There was a lengthy discussion here about whether
methods are objects or not. Strictly speaking they are not, but you
can obtain an object representing a bound or unbound method.
*I wish you a Merry Christmas and a Prosperous New Year 2011!!**
ed.update_signature!
Cheers
robert
···
On Tue, Jan 18, 2011 at 9:16 AM, Edmond Kachale <edmond.kachale@baobabhealth.org> wrote:
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.
···
On Tue, Jan 18, 2011 at 9:16 AM, Edmond Kachale <edmond.kachale@baobabhealth.org> 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.
--
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.
I think the conventional wisdom is that this should only be done only if there is a matching non-mutating method that has the name without the exclamation mark.
Gary Wright
···
On Jan 18, 2011, at 7:30 AM, Phillip Gawlowski wrote:
- 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.
Someone may give more info on why it should be like this:
···
Le 18 janvier 2011 22:01:11 UTC+2, Gary Wright <gwtmp01@mac.com> a écrit :
On Jan 18, 2011, at 7:30 AM, Phillip Gawlowski wrote:
>
> - 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.
I think the conventional wisdom is that this should only be done only if
there is a matching non-mutating method that has the name without the
exclamation mark.
I was going to try to explain this but why bother when David Black has already done a great job?
Gary Wright
···
On Jan 19, 2011, at 3:13 AM, Edmond Kachale wrote:
Le 18 janvier 2011 22:01:11 UTC+2, Gary Wright <gwtmp01@mac.com> a écrit :
On Jan 18, 2011, at 7:30 AM, Phillip Gawlowski wrote:
- 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.
I think the conventional wisdom is that this should only be done only if
there is a matching non-mutating method that has the name without the
exclamation mark.
Someone may give more info on why it should be like this:
On Jan 19, 2011, at 3:13 AM, Edmond Kachale wrote:
> Le 18 janvier 2011 22:01:11 UTC+2, Gary Wright <gwtmp01@mac.com> a écrit
:
>
>> On Jan 18, 2011, at 7:30 AM, Phillip Gawlowski wrote:
>>> obj.remove_name!
>>> obj.date! "Julian" # I wish I could do obj.date "Julian"!, instead. Ah,
>> well.
>>
>> I think the conventional wisdom is that this should only be done only if
>> there is a matching non-mutating method that has the name without the
>> exclamation mark.
>
>
> Someone may give more info on why it should be like this:
>
I think you left something off. Anyway...
Here is a great explanation of the '!' naming convention: