I will write an article as a substitute for a memo for studying.
Ruby method names can end with? By convention, methods ending in? Are methods that return boolean values.
#True if empty string, false otherwise
''.empty? #=> true
'abc'.empty? #=> false
#True if the argument string is included, false otherwise
'movie'.include?('mo') #=> true
'movie'.include?('at') #=> false
#True if odd, false otherwise
3.odd? #=> true
4.odd? #=> false
You can define the methods that end with?
#Returns true if it is a multiple of 2, otherwise false
def multiple_of_two?(n)
n % 2 == 0
end
multiple_of_two(1) #=> false
multiple_of_two(2) #=> true
multiple_of_two(3) #=> false
If the method is intended to return a boolean value, it is better to end it with?.
Recommended Posts