Skip to content
Related Articles

Related Articles

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

The to_s() is an inbuilt method in Ruby returns a string containing the given range.

Syntax: range1.to_s()

Parameters: The function accepts no parameter.

Return Value: It returns a string containing the range.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for to_s() 
# method in Range 
  
# Initialize range 
range1 = (0..4)
  
# Prints the string
puts range1.to_s()

chevron_right


Output:

0..4
Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for to_s() 
# method in Range 
  
# Initialize range 
range1 = (7..9)
  
# Prints the string
puts range1.to_s()

chevron_right


Output:

7..9
My Personal Notes arrow_drop_up
Recommended Articles
Page :