一般輸出

print "字串等等的"
puts "會有換行的字串"

簡易字串處理

"Takeshi".length # -> 7
"Takeshi".reverse # -> "ihsekaT"
"Takeshi".upcase # -> "TAKESHI"
"Takeshi".downcase # -> "takeshi"
"takeshi".capitalize # -> "Takeshi"

註解

# 單行
=begin

多行註解

=end

基本運算

# 跟 Python 差不多,不做筆記了

簡易字串格式化

"#{some_var}" # -> 會把變數套用進字串中

「!」用法

name = "Takeshi"
name.upcase!  # 等同於 name = name.upcase

基本輸入

something = gets  # gets 會把換行吃進去
something.chomp!  # 若要把換行去掉則可以使用 chomp

 

Share Your Thought