0

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
ndnenkov
  • 35,425
  • 9
  • 72
  • 104
David Sawatske
  • 111
  • 1
  • 7

2 Answers2

3

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.

ndnenkov
  • 35,425
  • 9
  • 72
  • 104
1

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.

Alejandro C.
  • 3,771
  • 15
  • 18