[Ruby]swapcaseで文字列の中の大文字と小文字を入れ替える

環境
Windows 10 Home 64bit
ruby 3.1.2p20

書式
文字列.swapcase
swapcaseメソッドは文字列の中の大文字と小文字を入れ替えます。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
target = "Study Skill"
target2 = "ArkGame"
puts target.swapcase
puts target2.swapcase
target = "Study Skill" target2 = "ArkGame" puts target.swapcase puts target2.swapcase
target = "Study Skill"
target2 = "ArkGame"

puts target.swapcase
puts target2.swapcase

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
C:\study\skill\ruby>ruby test.rb
sTUDY sKILL
aRKgAME
C:\study\skill\ruby>ruby test.rb sTUDY sKILL aRKgAME
C:\study\skill\ruby>ruby test.rb
sTUDY sKILL
aRKgAME

 

Ruby

Posted by arkgame