Ruby 의 치환에 대하여 간단히 설명드립니다.
$ cat test.rb sarc = "sarc" sarc.sub! "sarc","tomcat" puts sarc $ ruby test.rb tomcat
sub! 를 사용하여 sarc 을 tomcat 으로 바꾸었습니다. 참고로 gsub! 도 가능합니다. (Glocal Substitution)
$ cat test.rb sarc = "tomcat jboss apache nginx" sarc["tomcat"] = "shecat" puts sarc $ ruby test.rb shecat jboss apache nginx
tomcat 을 shecat 으로 바꾸었습니다.
$ cat test.rb sarc = "SARC" puts sarc.downcase $ ruby test.rb sarc
대문자를 소문자로 바꾸었습니다. upcase 를 사용하면 대문자로 바꿀 수 있습니다.
$ cat test.rb sarc = "sarc" puts sarc.capitalize $ ruby test.rb Sarc
첫글자를 대문자로 바꾸었습니다.