看板 Ruby 關於我們 聯絡資訊
我在別人的程式碼看這種寫法: module Twitter module Bootstrap module Rails require 'twitter/bootstrap/rails/engine' if defined?(Rails) end end end require 'less-rails' require 'twitter/bootstrap/rails/bootstrap' if defined?(Rails) 出處: http://tinyurl.com/d8yzeoj 如題,require 只是 load 檔案而已, 不像 include 會因不同位置而 mix-in 的對象不同。 所以我覺得這樣有點多餘,想問這樣寫有什麼特殊效果嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.227.144.248
godfat:看來沒意義,那個 if defined?也是沒意義,因為他自己定義了 07/26 15:04
mars90226:下面那個if defined?有意義,上面的就沒差了 07/26 19:58