Skip to content
Related Articles

Related Articles

Ruby | Range member? function

Improve Article
Save Article
  • Last Updated : 06 Jan, 2020
Improve Article
Save Article

The member?() 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.member?(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:




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

Output:

true
false

Example 2:




# Ruby program for member? method in Range 
  
# Initialize range 
range1 = (2..15)
  
# Prints if lies or not 
puts range1.member?(6)
puts range1.member?(13)

Output:

true
true
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!