Skip to content
instance method

Range#to_s

() -> ::String
to_s → string

Returns a string representation of self, including begin.to_s and end.to_s:

Example
(1..4).to_s  # => "1..4"
(1...4).to_s # => "1...4"
(1..).to_s   # => "1.."
(..4).to_s   # => "..4"

Note that returns from to_s and inspect may differ:

Example
('a'..'d').to_s    # => "a..d"
('a'..'d').inspect # => "\"a\"..\"d\""

Related: Range#inspect.

See also #to_json #to_set #to_a also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0