Does a method that ends with a question mark?

Does a method that ends with a question mark have to return a boolean in Crystal?

for example:

def isTomato?(color : String, shape : String)
  color == "red" && (shape == "round" || shape == "sphere")
end

Does this differ if it’s a function outside of a class or if its a method in a class?

No, there is no need to return a boolean.

In many places of the std-lib a you might found a method foo that raises and foo? that return nil instead of error. For example Array#[] vs Array#[]? in case of an index out-of-bounds.

They are like any other method.

1 Like

Thank you!