Reputation: 249
How do you define a method of verification? The example: include? even? odd?
>> 2.odd?
=> false
>> 6.even?
=> true
>>
Upvotes: 1
Views: 4864
Reputation: 80065
class Integer
def is_even?
self.remainder(2) == 0
# this is either true or false, just what we want
end
end
p 4.is_even?
#=> true
Upvotes: 5
Reputation: 14619
The same way you define any other function - the question mark is part of the function name:
def is_it?
return (...)
end
Cheers!
Upvotes: 10