randomguy
randomguy

Reputation: 12252

What is the favorable naming convention for methods or properties returning a boolean value in Ruby?

I've seen all of these:

Is there a preferred one?

EDIT: More conditionals:

Please do add more descriptive examples.

Upvotes: 3

Views: 165

Answers (2)

iNecas
iNecas

Reputation: 1793

In favor of trying the code to be 'natural language' like, is_valid? should be most suitable for me. Lets show an example:

if @order.is_valid? @order.save end

Upvotes: 1

willcodejavaforfood
willcodejavaforfood

Reputation: 44103

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

  • valid?

Upvotes: 8

Related Questions