Reputation: 111
Is it poor practice to name the variable in a method a lowercase version of the class name?
In the case below: string.class
==> String
def title=(string)
@title = string.split(' ').map.with_index do |word, i|
i == 0 ? word.capitalize : title_form(word)
end.join(' ')
end
Upvotes: 0
Views: 67
Reputation: 36110
Depends. You want to be using names as close as possible to the problem domain.
In your case, a more appropriate name for the parameter would be uncapitalized_title
, raw_title
, unformatted_title
, simply title
or something similar.
On the other hand, if you were writing a gem that extends String
or does something with generic strings, then string
is likely the right name.
Upvotes: 3
Reputation: 3801
It is poor practice, because it's usually not very descriptive. Additionally, since Ruby doesn't actually care that you're passing a string
it could be misleading.
Upvotes: 1