2014年7月1日 星期二

Codecademy - 1. Introduction to Ruby

    之前發現了codecademy這個網站,對於想學新的語言但不知從何開始的人來說實在是一大好物,學習Ruby之際做了些筆記,當作之後可以複習之用!!




學習重點:
1. 結尾不用分號

2. 字串用" "來包住

3. 數字宣告範例 : num = 66

4. print 和 puts是輸出的method,差別為puts會自動斷行

5. 字串的method要能夠活用(.length ; .reverse ; .upcase ; .downcase)

6. 註解如果是單行的話,寫法如下:
    # Length method test
    多行則為:
     =begin
     WOW!! I am starting to learn Ruby!!
     It's amazing!!
     =end
7. 從螢幕得到輸出的method為:
    gets.chomp(不加.chomp也可以,不過會得到一個blank line)

8. 如果要在輸出中帶變數的話,參考以下範例:
    puts "Your name if #{first_name} #{last_name} from #{city} #{state}!"

沒有留言:

張貼留言