SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
30分鐘技術分享
         Ruby小觀念&技巧 Part 2 By Bruce Li




          2012/04/19
          雲端線上科技股份有限公司

12年4月21日星期六
這次要講三個東西

              • require, load, include
              • yield
              • method的參數


12年4月21日星期六
require, load, include



12年4月21日星期六
require vs. load




12年4月21日星期六
require vs. load
 跳 過




12年4月21日星期六
require vs. load
 跳 過


                值都⼀一樣




12年4月21日星期六
require vs. load
 跳 過


                       值都⼀一樣

              ⼀一 次
      loa d了
  又




12年4月21日星期六
require vs. load
 跳 過


                       值都⼀一樣

              ⼀一 次
      loa d了
  又

                       值很可能不同


12年4月21日星期六
關於require/load的參數

              • require跟load都是吃字串
              • load必須提供附檔名,require則可忽略
              • 自己寫的檔案不指定目錄的話,都會掛


12年4月21日星期六
解決相對目錄問題
                指明絕對路徑




              /Users/bruce/Desktop/../var.rb
              = /Users/bruce/var.rb

                               /Users/bruce/Desktop/var.rb

12年4月21日星期六
解決相對目錄問題
              指明絕對路徑




12年4月21日星期六
require vs. include




  module跟class寫在同⼀一個檔案當然也是可以include的
               這樣就不需先要require
12年4月21日星期六
補充:這樣也是可以的




12年4月21日星期六
include lib下的module (rails)

          • rails 2的時候是可以直接include的
          • rails 3的時候因為安全性考量,
              include前需要先require

          • require "authenticated_system"
              => require RailsRoot/lib/authenticated_system.rb



12年4月21日星期六
module命名
                  名詞




                       形容詞


              非強制,不過這樣還蠻有道理的
12年4月21日星期六
yield



12年4月21日星期六
用來測效能




              => 1.2011590003967285
12年4月21日星期六
yield的參數




12年4月21日星期六
yield的參數

                    2
                    4
                    6




12年4月21日星期六
yield的參數



                         2
                         4
                         6



12年4月21日星期六
method的參數



12年4月21日星期六
選擇性參數/預設值




12年4月21日星期六
不定數量參數




12年4月21日星期六
不定數量參數




12年4月21日星期六
類似的:hash




12年4月21日星期六
混用的順序




12年4月21日星期六
混用的順序 - hash


                            √


              省略{ }的hash要在固定參數之後
                要不然就明確的指定 { }

12年4月21日星期六
end



12年4月21日星期六
廣告
              雲端線上徵Rails/iOS/Android工程師中

               ‣ inside job board
              我的技術&生活雜事部落格

               ‣ http://littlebmix.blogspot.com/
              學習成功部落格

               ‣ http://ascend-er.blogspot.com/
12年4月21日星期六

Weitere ähnliche Inhalte

Mehr von Bruce Li

Unlock dependency between client teams and API team with API mock and proxy
Unlock dependency between client teams and API team with API mock and proxyUnlock dependency between client teams and API team with API mock and proxy
Unlock dependency between client teams and API team with API mock and proxyBruce Li
 
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)Bruce Li
 
Rails Code Club 3 @ Taipei
Rails Code Club 3 @ TaipeiRails Code Club 3 @ Taipei
Rails Code Club 3 @ TaipeiBruce Li
 
010 Better and Better 工程師就業兩年多的心得雜談
010 Better and Better 工程師就業兩年多的心得雜談010 Better and Better 工程師就業兩年多的心得雜談
010 Better and Better 工程師就業兩年多的心得雜談Bruce Li
 
009 增進效率的雜七雜八mac快速鍵與設定 part 2
009 增進效率的雜七雜八mac快速鍵與設定 part 2009 增進效率的雜七雜八mac快速鍵與設定 part 2
009 增進效率的雜七雜八mac快速鍵與設定 part 2Bruce Li
 
008 vim超基礎入門
008 vim超基礎入門008 vim超基礎入門
008 vim超基礎入門Bruce Li
 
006 實作小玩具功能:chrome desktop notification
006 實作小玩具功能:chrome desktop notification006 實作小玩具功能:chrome desktop notification
006 實作小玩具功能:chrome desktop notificationBruce Li
 
004 動機 單純的力量 讀書心得
004 動機 單純的力量 讀書心得004 動機 單純的力量 讀書心得
004 動機 單純的力量 讀書心得Bruce Li
 
002 增進效率的有的沒的快速鍵與設定
002 增進效率的有的沒的快速鍵與設定002 增進效率的有的沒的快速鍵與設定
002 增進效率的有的沒的快速鍵與設定Bruce Li
 

Mehr von Bruce Li (9)

Unlock dependency between client teams and API team with API mock and proxy
Unlock dependency between client teams and API team with API mock and proxyUnlock dependency between client teams and API team with API mock and proxy
Unlock dependency between client teams and API team with API mock and proxy
 
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
 
Rails Code Club 3 @ Taipei
Rails Code Club 3 @ TaipeiRails Code Club 3 @ Taipei
Rails Code Club 3 @ Taipei
 
010 Better and Better 工程師就業兩年多的心得雜談
010 Better and Better 工程師就業兩年多的心得雜談010 Better and Better 工程師就業兩年多的心得雜談
010 Better and Better 工程師就業兩年多的心得雜談
 
009 增進效率的雜七雜八mac快速鍵與設定 part 2
009 增進效率的雜七雜八mac快速鍵與設定 part 2009 增進效率的雜七雜八mac快速鍵與設定 part 2
009 增進效率的雜七雜八mac快速鍵與設定 part 2
 
008 vim超基礎入門
008 vim超基礎入門008 vim超基礎入門
008 vim超基礎入門
 
006 實作小玩具功能:chrome desktop notification
006 實作小玩具功能:chrome desktop notification006 實作小玩具功能:chrome desktop notification
006 實作小玩具功能:chrome desktop notification
 
004 動機 單純的力量 讀書心得
004 動機 單純的力量 讀書心得004 動機 單純的力量 讀書心得
004 動機 單純的力量 讀書心得
 
002 增進效率的有的沒的快速鍵與設定
002 增進效率的有的沒的快速鍵與設定002 增進效率的有的沒的快速鍵與設定
002 增進效率的有的沒的快速鍵與設定
 

003 Ruby小觀念與小技巧Part2