Ruby/String/reverse
Материал из Wiki.crossplatform.ru
Версия от 17:56, 13 сентября 2010; ViGOur (Обсуждение | вклад)
Содержание |
Call reverse function from returning value from update function
"Test".upcase.reverse
Call reverse function from string class
"Test".reverse
Reverse a palindrome:
palindrome = "dennis sinned" palindrome.reverse! p palindrome
Reverse a string in or not in place
s = ".sdrawkcab si gnirts sihT" puts s.reverse puts s s.reverse! # => "This string is backwards." puts s # => "This string is backwards."
To reverse the characters means to alter the characters so they read in the opposite direction.
puts "abcdefghijklmnopqrstuvwxyz".reverse