Skip to content

Latest commit

 

History

History
68 lines (48 loc) · 1.09 KB

File metadata and controls

68 lines (48 loc) · 1.09 KB

Ruby

##CodeCademy

####basic

3 ** 3 

3的3次方

string.length

tring.reverse

string.upcase

轉大寫
string.downcase 轉小寫

#單行註解   
=begin 多行註解 =end

註解

name = "Kettan"

宣告變數

.method可以這樣用: name = name.reverse.downcase.upcase

name = gets.chomp name等於使用者輸入的字串

puts "Hello, #{name}" 印出Hello, 名字

name = get.chomp.capitalize! 把輸入的字串第一個字變成大寫

user_int = Integer(gets.chopm) 取得輸入的整數

if true   
  puts 'hello'   
elsif   
  puts 'œøōõ'   
end    
#要加end 注意這裡的elseif要打成elsif   

unless hungry
  puts "I'm writing Ruby programs!"
else
  puts "Time to eat!"
end 
#unless用法  
wrong = false
puts 'Cool' unless wrong

印出兩個"""中間包起來的內容

puts """
With the three double-quotes.
We'll be able to type as much as we like.
Even 3 lines if we want, or 4, or 10.
"""