Skip to content

Instantly share code, notes, and snippets.

@taiansu
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taiansu/d88d15ad2e1b04573f4d to your computer and use it in GitHub Desktop.
Save taiansu/d88d15ad2e1b04573f4d to your computer and use it in GitHub Desktop.
Explaination
# puts something 等同於 puts something.to_s 所以都會自動轉字串
# p something 等同於 puts something.inspect 會印出比較詳細的資料,通常是 debug 用。
# 當你在
def method
"aaa"
end
# 等同於
def method
return "aaa"
end
# 第四題
def scream(words)
words = words + "!!!!"
return # 這裡等同於 return nil,所以回傳一個空值
#因為已經 return 了,從此以下永遠不會執行到。所以也不會有錯。
puts words
end
# 最 ruby 的正確寫法是
def scream(words)
puts "#{words}!!!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment