嗯,记录一下只是为了避免如果中断很久之后还能记得……
我是不是特别蛋疼 Orz……
学习来源:Code Cademy,一个很好的在线自学 coding 网站,除了 Ruby 以外还有诸如 HTML&CSS(这其实才是我最初原定的计划)、jQuery、Java 一类的语言。虽然只有英文,但阅读基本无障碍。
原本学习平台的首选其实是 RubyMonk,但是不知道为什么中文版的 Ruby 初学者 无法查看代码运行结果,只好吭哧吭哧看英文……
第一课 Putting the Form in Formatter.
主要是这些东西:
methods 包括:.length .upcase .downcase .capitalize .swapcase,可以放在连续一行里,也可以换行。
puts 和 print 的区别,额外的还有 p
gets 和 gets.chomp 的区别
输出:#{变量}
一个Demo:
print “What’s your first name?”
first_name = gets.chomp
first_name.capitalize!
print “What’s your last name?”
last_name = gets.chomp
last_name.capitalize!
print “Which city are you from?”
city = gets.chomp
city.capitalize!
print “Which country?”
state = gets.chomp
state.upcase!
puts “My name is #{first_name} #{last_name}, I’m from #{city}, #{state}.”
最后,没太搞懂案例里多行命令的 =begin =end 和 #单行命令 的使用和区别……
第二课 Control Flow
已有 = 时,用 == 代表相等,!= 代表不等。
boolean:与 (&&), 或 (||), 非 (!).
if, else, elsif, end