Last active
March 6, 2019 15:29
-
-
Save andy922200/a7a7b26267f4910621316b0d87778b75 to your computer and use it in GitHub Desktop.
Learn Ruby on Rails - Codecademy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .reverse 的用法,倒轉字串 | |
a = "simultaneously" | |
puts a.reverse | |
# .upcase & .downcase,轉換大小寫 | |
a = "simultaneously" | |
puts a.upcase | |
puts a.downcase | |
# =begin & =end 搭配,將一個範圍裡的 Code 都不被解讀。 | |
=begin | |
This is for a test. | |
=end | |
# 用#{XXX}印出變數的值 | |
my_name = "Andy" | |
my_age = 28 | |
puts "My name is #{my_name}" | |
puts "My age is #{my_age}" | |
# String methods,可以連續下指令 | |
name = "Andy".downcase.reverse.upcase | |
puts name | |
# .include?,確認是否有某字串,並用.gsub! 給予取代 (/xxx/,"yyy") | |
if user_input.include? "s" | |
user_input.gsub!(/s/,"th") | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment