0

I have a method:

def addNewShow(name)

end

I want it to return a boolean which states whether or not this was successful. Should my method have a question mark on the end of its name to let the user know that that's what it returns, despite it not being a question, and only returning the answer to the question "Was this successful?"

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Andrew
  • 15,935
  • 28
  • 121
  • 203
  • 4
    No, not unless the method name is suitable as a question. Your method is a verb "add". If it was "added_show?" and tested to see if a particular "show" was added, then yes, it'd make sense. Also, in Ruby, method names are not CamelCase, they're snake_case. – the Tin Man Aug 10 '13 at 00:31
  • This has already been answered here http://stackoverflow.com/questions/4289629/in-ruby-is-truthiness-idiomatic-for-a-method-name-ending-with-a-question-mark?rq=1 – Shyam Habarakada Aug 10 '13 at 01:17
  • @ShyamHabarakada No, that’s the inverse of this question. – Andrew Marshall Aug 10 '13 at 04:08

1 Answers1

1

I don't think it's necessary for that. You could include a method to check if a show already exists though:

def exists?(show_name)
  #your code to check if it exists
  #return boolean value of true/false for if show is already added or not
end
tigeravatar
  • 26,199
  • 5
  • 30
  • 38
  • 1
    It is not Ruby's practice to use third-person singular present method names besides a few exceptions (`is_a?`, etc). – sawa Aug 10 '13 at 03:55
  • n/m, I read it as "Is it not" rather than "It is not", herp derp. What is Ruby's practice then, and is it documented somewhere? – tigeravatar Aug 10 '13 at 04:20
  • 1
    http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/5599, http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/5579 – sawa Aug 10 '13 at 04:31