Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

String#reverse

() -> ::String
reverse → new_string

Returns a new string with the characters from self in reverse order.

Example
'drawer'.reverse       # => "reward"
'reviled'.reverse      # => "deliver"
'stressed'.reverse     # => "desserts"
'semordnilaps'.reverse # => "spalindromes"

Related: see Converting to New String.

Ruby version changes

  1. 3.0
See also #reverse! #replace #prepend #rindex also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0