What Does the "?" at the End of the Ruby Array#include? Method Mean?

The Ruby Array#include? method has a question mark symbol after the method name because it returns a boolean value (i.e. true/false):

array = ["foo", "bar", "baz"]

puts array.include?("foo") #=> true
puts array.include?("qux") #=> false

In Ruby, method names ending with a question mark (?) is a naming convention for methods that either return true/false, or an object to indicate a true value (or "truthy" value).

Please note that this convention only applies to method names and not variables.


This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.