本節(jié)內(nèi)容東坡小編為大家整理帶來(lái)的是一份pdf格式最新整理版且內(nèi)容完整免費(fèi)的Ruby教程——準(zhǔn)確一點(diǎn)來(lái)說(shuō),應(yīng)該是Ruby語(yǔ)法基礎(chǔ)教程,該教程共有134頁(yè),詳細(xì)介紹了Ruby的歷史、Ruby名字的由來(lái)、Ruby的安裝等相關(guān)內(nèi)容,是一份非常不錯(cuò)的ruby教程,有需要的朋友們可千萬(wàn)不要錯(cuò)過(guò)哦!
Ruby語(yǔ)法基礎(chǔ)教程目錄
第一部分 Ruby 語(yǔ)言基礎(chǔ) ....................................................... 8
第一章 Ruby 語(yǔ)言概述 .......................................................... 8
§1.1 Ruby 的歷史 ....................................................................... 8
§1.2 Ruby 名字的由來(lái) ................................................................... 8
§1.3 Ruby 的特點(diǎn) ....................................................................... 8
§1.4 Ruby 和 Python 的比較 ............................................................... 9
第二章 Ruby 編程環(huán)境 .......................................................... 9
§2.1 Ruby 的安裝 ...................................................................... 9
§2.1.1 在 Windows 95/98/Me/XP 上安裝 Ruby ........................................... 9
§2.1.2 在 Linux 上安裝 Ruby ........................................................ 10
§2.2 運(yùn)行 Ruby ....................................................................... 10
§2.2.1 使用 Ruby ................................................................. 10
§2.2.2 使用 FreeRIDE 和 SciTE ...................................................... 12
§2.2.3 使用 fxri ................................................................. 13
§2.3 Ruby-irb ........................................................................ 14
§2.4 Ruby-ri ......................................................................... 15
§2.5 RubyGems ........................................................................ 16
類(lèi)與對(duì)象 ..................................................................... 17
§3.1 類(lèi)的定義 ......................................................................... 17
§3.2 對(duì)象,屬性和方法 ................................................................. 18
§3.3 繼承 ............................................................................. 21
§3.4 特殊方法與特殊類(lèi) ................................................................. 23
§3.5 類(lèi)變量與類(lèi)方法 ................................................................... 24
§3.4 存取控制 ......................................................................... 25
§3.6 元類(lèi) ............................................................................. 27
§3.7 Ruby 的動(dòng)態(tài)性 .................................................................... 28
§3.8 變量 ............................................................................. 29
§3.8.1 局部變量 ................................................................... 29
§3.8.2 實(shí)例變量 ................................................................... 30
§3.8.3 類(lèi)變量 ..................................................................... 30
§3.8.4 全局變量 ................................................................... 31
§3.8.5 常量 ....................................................................... 31
§3.8 與定義有關(guān)的操作 ................................................................. 32
§3.8.1 alias ...................................................................... 32
§3.8.2 undef ...................................................................... 33
§3.8.3 defined? ................................................................... 34
第四章 基本類(lèi)型 .............................................................. 37
§4.1 Array ............................................................................ 37
§4.2 Hash ............................................................................. 38
§4.3 Number ........................................................................... 39
§4.4 String ........................................................................... 40
§4.5 Range ............................................................................ 41
§4.6 Symbol ........................................................................... 42
§4.7 正則表達(dá)式 ....................................................................... 43
3
第五章 代碼塊和迭代器 ........................................................ 44
§5.1 代碼塊 (Block) .................................................................... 44
§5.1.1 什么是代碼塊 ................................................................ 44
§5.1.2 代碼塊與對(duì)象 ................................................................ 44
§5.2 迭代器 (Iterator) ................................................................. 46
§5.2.1 什么是迭代器 ................................................................ 46
§5.2.2 使用迭代器 .................................................................. 46
§5.2.3 yield ....................................................................... 47
§5.2.4 編寫(xiě)自己的迭代器 ............................................................ 48
第六章 表達(dá)式 ................................................................ 49
§6.1 運(yùn)算符 ........................................................................... 49
§6.2 命令替換 ......................................................................... 51
§6.3 賦值運(yùn)算符 ....................................................................... 51
§6.4 并行賦值 ......................................................................... 53
§6.5 嵌套賦值 ......................................................................... 54
§6.6 其他賦值 ......................................................................... 54
§6.7 條件運(yùn)算 ......................................................................... 54
§6.8 case 表達(dá)式 ...................................................................... 56
§6.9 循環(huán) ............................................................................. 57
§6.9.1 Loop ........................................................................ 57
§6.9.2 While ....................................................................... 58
§6.9.3 Until ....................................................................... 58
§6.9.4 Iterator .................................................................... 58
§6.9.5 For..In ..................................................................... 59
§6.9.6 Break , Redo , Next ........................................................... 59
§6.9.7 Retry ....................................................................... 62
第七章 方法 .................................................................. 63
§7.1 運(yùn)算符重定義 .................................................................. 65
§7.2 變長(zhǎng)參數(shù) ...................................................................... 65
§7.3 塊調(diào)用 ........................................................................ 66
§7.4 方法返回值 .................................................................... 67
第八章 模塊 .................................................................. 69
§8.1 名字空間 ......................................................................... 69
§8.2 mixin ............................................................................ 70
§8.3 使用 mixin ....................................................................... 71
§8.3.1 Comparable ................................................................. 71
§8.3.2 Enumerable ................................................................. 72
§8.3.3 Singleton .................................................................. 73
§8.4 Require, load 和 include .......................................................... 74
異常 75
§9.1 異常處理 .......................................................................... 75
§9.2 定義異常類(lèi) ........................................................................ 80
§9.3 catch 和 throw ..................................................................... 80
多任務(wù)處理 ................................................................... 81
§10.1 多線(xiàn)程處理 ...................................................................... 82
§10.1.1 線(xiàn)程創(chuàng)建 .................................................................. 82
§10.1.2 線(xiàn)程操作 .................................................................. 83
4
§10.1.3 線(xiàn)程和異常 ................................................................ 84
§10.1.4 線(xiàn)程調(diào)度 .................................................................. 86
§10.1.5 線(xiàn)程同步 .................................................................. 87
§10.2 多進(jìn)程處理 ...................................................................... 93
§10.2.1 進(jìn)程創(chuàng)建 .................................................................. 94
基本 I/O 操作 ................................................................. 95
§11.1 使用 Kernel 模塊處理 I/O 操作 ...................................................... 95
§11.2 文件處理 ......................................................................... 95
§11.3 StringIO ......................................................................... 96
§11.4 Socket ........................................................................... 97
第十二章 反射和對(duì)象空間 ...................................................... 98
§12.1 ObjectSpace 模塊 ................................................................ 98
§12.2 察看類(lèi)和對(duì)象的狀態(tài) .............................................................. 99
§12.3 動(dòng)態(tài)方法調(diào)用 ................................................................... 102
§12.3.1 使用 send 方法 ............................................................ 102
§12.3.2 使用 Method 類(lèi)和 UnboundMethod 類(lèi) .......................................... 103
§12.3.3 使用 eval 方法 ............................................................ 104
§12.3.4 性能 ..................................................................... 105
§12.4 Hook 和回調(diào)方法 ................................................................ 106
§12.4.1 什么是 Hook .............................................................. 106
§12.4.2 Ruby 中的 Hook ............................................................ 106
§11.4.2 回調(diào)方法 ................................................................. 107
§12.5 跟蹤程序的運(yùn)行 ................................................................. 108
§12.5.1 set_trace_func ........................................................... 108
§12.5.2 trace_var ................................................................ 109
§12.5.3 caller ................................................................... 109
§12.5.3 __FILE__,__LINE__ 和 SCRIPT_LINES__ ........................................ 109
第十三章 序列化和 YAML ...................................................... 110
§13.1 序列化的概念 ................................................................... 110
§13.2 使用序列化 ..................................................................... 110
§13.2.1 二進(jìn)制數(shù)據(jù)保存 ........................................................... 110
§13.2.2 YAML 數(shù)據(jù)保存 ............................................................ 111
§13.3 定制序列化 ..................................................................... 112
§13.3.1 二進(jìn)制數(shù)據(jù)保存 ........................................................... 112
§13.3.2 YAML 數(shù)據(jù)保存 ............................................................ 113
§13.3 YAML ........................................................................... 114
§13.3.1 集合類(lèi)型 ................................................................. 115
§13.3.2 單行集合類(lèi)型 ............................................................. 118
§13.3.3 基本類(lèi)型 ................................................................. 118
§13.3.4 塊 ....................................................................... 119
§13.3.5 別名和錨( Aliases and Anchors ) .......................................... 119
§13.3.6 文檔 ..................................................................... 119
§13.3.7 Ruby 中 YAML 的使用 ........................................................ 119
第十四章 安全控制 ........................................................... 120
§14.1 0 級(jí) ........................................................................... 121
§14.1 1 級(jí) ........................................................................... 121
§14.2 2 級(jí) ........................................................................... 121
5
§14.3 3 級(jí) ........................................................................... 121
§14.4 4 級(jí) ........................................................................... 121
第十五章 單元測(cè)試 ........................................................... 122
§15.1 什么是單元測(cè)試 ................................................................. 122
§15.2 Ruby 單元測(cè)試框架 .............................................................. 122
第二部分 內(nèi)置類(lèi)與模塊 ...................................................... 122
第一章 內(nèi)置類(lèi) ............................................................... 122
§1.1 Array ............................................................................ 122
§1.2 Bignum ........................................................................... 123
§1.3 Binding .......................................................................... 123
§1.4 Class ............................................................................ 123
§1.5 Continuation ..................................................................... 123
§1.6 Dir .............................................................................. 125
§1.7 Exception ........................................................................ 125
§1.8 FalseClass ....................................................................... 125
§1.9 File ............................................................................. 125
§1.10 File::Stat ...................................................................... 125
§1.11 Fixnum .......................................................................... 125
§1.12 Float ........................................................................... 125
§1.13 Hash ............................................................................ 125
§1.14 Integer ......................................................................... 125
§1.15 IO .............................................................................. 125
§1.16 MatchData ....................................................................... 125
§1.17 Method .......................................................................... 125
§1.18 Module .......................................................................... 125
§1.19 NilClass ........................................................................ 126
§1.20 Numeric ......................................................................... 126
§1.21 Object .......................................................................... 126
§1.22 Proc ............................................................................ 126
§1.23 Process::Status ................................................................. 126
§1.24 Range ........................................................................... 126
§1.25 Regexp .......................................................................... 126
§1.26 String .......................................................................... 126
§1.27 Struct .......................................................................... 126
§1.28 Struct::Tms ..................................................................... 126
§1.29 Symbol .......................................................................... 126
§1.30 Thread .......................................................................... 126
§1.31 ThreadGroup ..................................................................... 126
§1.32 Time ............................................................................ 127
§1.33 TrueClass ....................................................................... 127
§1.34 UnboundMethod ................................................................... 127
第二章 內(nèi)置模塊 ............................................................. 128
§2.1 Comparable ....................................................................... 128
§2.2 Enumerable ....................................................................... 128
§2.3 Error ............................................................................ 128
§2.4 FileTest ......................................................................... 128
§2.5 GC ............................................................................... 128
6
§2.6 Kernel ........................................................................... 128
§2.7 Marshal .......................................................................... 128
§2.8 Math ............................................................................. 128
§2.9 ObjectSpace ...................................................................... 128
§2.10 Process ......................................................................... 128
§2.11 Process :: GID .................................................................. 128
§2.12 Process :: Sys .................................................................. 128
§2.13 Process :: UID .................................................................. 129
§2.14 Signal .......................................................................... 129
第三部分 Ruby 語(yǔ)言總結(jié) ..................................................... 130
附錄 134
§1 術(shù)語(yǔ)對(duì)照 .......................................................................... 134
Ruby語(yǔ)法基礎(chǔ)教程內(nèi)容截圖
- PC官方版
- 安卓官方手機(jī)版
- IOS官方手機(jī)版