Ruby | Range include?() function
The include?() is an inbuilt method in Ruby returns a boolean value true if the given object lies within the given range, else it returns false.
Syntax: range1.include?(obj)
Parameters: The function accepts an object which is to be checked for.
Return Value: It returns a boolean value true if the given object lies within the given range, else it returns false.
Example 1:
range1 = ( 0 .. 10 )
puts range1.include?( 6 )
puts range1.include?( 13 )
|
Output:
true
false
Example 2:
range1 = ( 2 .. 5 )
puts range1.include?( 7 )
puts range1.include?( 11 )
|
Output:
false
false
Last Updated :
19 Mar, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...