What is the meaning of ? in ruby

Hi guys,
I really need help understanding what the questions mark in the method below represents

def who_am_i?

It’s purely part of the method name. In Ruby, you can add punctuation like !, ?, =, etc. The question mark is nothing special.

Thanks Ryan

I’m not sure it’s good practise to end a normal method with a question mark in Ruby. This is because in Ruby, there is a naming convention where predicate methods (those that return true or false) end with a question mark. For instance, if you have an Invoice class and are writing an instance method that returns whether the invoice has been paid or not, you would name the method paid?

I would probably call the method you describe something like get_user_name

You can read more here: http://pragmati.st/2012/03/24/the-elements-of-ruby-style-predicate-methods/

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.