What favorable naming convention for methods or properties returns a boolean value in Ruby?

I saw it all:

  • is_valid

  • is_valid?

  • valid?

Is there a preferred option?

EDIT: Additional Terms:

  • has_comment has_comment? comment?

  • was_full was_full? full?

Please add more detailed examples.

+3
source share
2 answers

I think the convention is basically to add '?' at the end of the method instead of 'is'

  • valid?
+8
source

In favor of a code attempt to be a "natural language" like is_valid? should be the most suitable for me. Let's show an example:

if @ order.is_valid? @ order.save end

+1
source

Source: https://habr.com/ru/post/1766416/


All Articles