Skip to content
Related Articles

Related Articles

Ruby | Range include?() function
  • Last Updated : 06 Jan, 2020

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for include? method in Range 
  
# Initialize range 
range1 = (0..10)
  
# Prints if lies or not 
puts range1.include?(6)
puts range1.include?(13

chevron_right


Output:

true
false

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for include? method in Range 
  
# Initialize range 
range1 = (2..5)
  
# Prints if lies or not 
puts range1.include?(7)
puts range1.include?(11)

chevron_right


Output:

false
false
My Personal Notes arrow_drop_up
Recommended Articles
Page :