Ruby | Range to_s() function Last Updated : 19 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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: Ruby # Ruby program for to_s() # method in Range # Initialize range range1 = (0..4) # Prints the string puts range1.to_s() Output: 0..4 Example 2: Ruby # Ruby program for to_s() # method in Range # Initialize range range1 = (7..9) # Prints the string puts range1.to_s() Output: 7..9 Comment More infoAdvertise with us Next Article Ruby | Range to_s() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Range-class Similar Reads Ruby | Range to_a() function The to_a() is an inbuilt method in Ruby returns an array containing the numbers in the given range. Syntax: range1.to_a() Parameters: The function accepts no parameter. Return Value: It returns an array containing all the numbers. Example 1: Ruby # Ruby program for to_a() # method in Range # Initial 1 min read Ruby | Regexp to_s() function Regexp#to_s() : to_s() is a Regexp class method which returns the string containing the regular expression with the same semantics. Syntax: Regexp.to_s() Parameter: Regexp values Return: string containing the regular expression with the same semantics. Example #1 : Ruby # Ruby code for Regexp.to_s() 1 min read Ruby | Range size() function The size() is an inbuilt method in Ruby returns the size of the range. It returns the number of elements in the range. Syntax: range1.size() Parameters: The function accepts no parameter. Return Value: It returns the number of elements in the range. Example 1: Ruby # Ruby program for size() # method 1 min read Ruby | Rational to_s() function The to_s() is an inbuilt function in Ruby returns value as string Syntax: rat.to_s() Parameters: The function accepts no parameter Return Value: It returns value as string Example 1: CPP #Ruby program for to_s() method #Initialize rational number rat1 = Rational(18, -4) #Prints the rational number p 1 min read Ruby | Hash to_s() function Hash#to_s() is a Hash class method which gives the string representation of hash. Syntax: Hash.to_s() Parameter: Hash values Return: string representation of hash Example #1 : Ruby # Ruby code for Hash.to_s() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, 1 min read Like