Reputation: 59
Could someone explain what the logic is behind the include?
method in the following context?
some_var = gets.chomp.to_i
until (1..12).include? some_var
print "Please, re-type it again!"
number = gets.chomp.to_i
end
Upvotes: 0
Views: 102
Reputation: 26968
Returns true if obj is an element of the range, false otherwise. If begin and end are numeric, comparison is done according to the magnitude of the values.
In ur question,
if some_var is within 1 -12 range, it will return true, otherwise , it will return false
Upvotes: 0
Reputation: 19853
When in doubt, go to the documentation: http://ruby-doc.org/core-2.0/Range.html#method-i-include-3F
Upvotes: 4