本节内容东坡小编为大家整理带来的是一份pdf格式最新整理版且内容完整免费的Ruby教程——准确一点来说,应该是Ruby语法基础教程,该教程共有134页,详细介绍了Ruby的历史、Ruby名字的由来、Ruby的安装等相关内容,是一份非常不错的ruby教程,有需要的朋友们可千万不要错过哦!
Ruby语法基础教程目录
第一部分 Ruby 语言基础 ....................................................... 8
第一章 Ruby 语言概述 .......................................................... 8
§1.1 Ruby 的历史 ....................................................................... 8
§1.2 Ruby 名字的由来 ................................................................... 8
§1.3 Ruby 的特点 ....................................................................... 8
§1.4 Ruby 和 Python 的比较 ............................................................... 9
第二章 Ruby 编程环境 .......................................................... 9
§2.1 Ruby 的安装 ...................................................................... 9
§2.1.1 在 Windows 95/98/Me/XP 上安装 Ruby ........................................... 9
§2.1.2 在 Linux 上安装 Ruby ........................................................ 10
§2.2 运行 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
类与对象 ..................................................................... 17
§3.1 类的定义 ......................................................................... 17
§3.2 对象,属性和方法 ................................................................. 18
§3.3 继承 ............................................................................. 21
§3.4 特殊方法与特殊类 ................................................................. 23
§3.5 类变量与类方法 ................................................................... 24
§3.4 存取控制 ......................................................................... 25
§3.6 元类 ............................................................................. 27
§3.7 Ruby 的动态性 .................................................................... 28
§3.8 变量 ............................................................................. 29
§3.8.1 局部变量 ................................................................... 29
§3.8.2 实例变量 ................................................................... 30
§3.8.3 类变量 ..................................................................... 30
§3.8.4 全局变量 ................................................................... 31
§3.8.5 常量 ....................................................................... 31
§3.8 与定义有关的操作 ................................................................. 32
§3.8.1 alias ...................................................................... 32
§3.8.2 undef ...................................................................... 33
§3.8.3 defined? ................................................................... 34
第四章 基本类型 .............................................................. 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 正则表达式 ....................................................................... 43
3
第五章 代码块和迭代器 ........................................................ 44
§5.1 代码块 (Block) .................................................................... 44
§5.1.1 什么是代码块 ................................................................ 44
§5.1.2 代码块与对象 ................................................................ 44
§5.2 迭代器 (Iterator) ................................................................. 46
§5.2.1 什么是迭代器 ................................................................ 46
§5.2.2 使用迭代器 .................................................................. 46
§5.2.3 yield ....................................................................... 47
§5.2.4 编写自己的迭代器 ............................................................ 48
第六章 表达式 ................................................................ 49
§6.1 运算符 ........................................................................... 49
§6.2 命令替换 ......................................................................... 51
§6.3 赋值运算符 ....................................................................... 51
§6.4 并行赋值 ......................................................................... 53
§6.5 嵌套赋值 ......................................................................... 54
§6.6 其他赋值 ......................................................................... 54
§6.7 条件运算 ......................................................................... 54
§6.8 case 表达式 ...................................................................... 56
§6.9 循环 ............................................................................. 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 运算符重定义 .................................................................. 65
§7.2 变长参数 ...................................................................... 65
§7.3 块调用 ........................................................................ 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 定义异常类 ........................................................................ 80
§9.3 catch 和 throw ..................................................................... 80
多任务处理 ................................................................... 81
§10.1 多线程处理 ...................................................................... 82
§10.1.1 线程创建 .................................................................. 82
§10.1.2 线程操作 .................................................................. 83
4
§10.1.3 线程和异常 ................................................................ 84
§10.1.4 线程调度 .................................................................. 86
§10.1.5 线程同步 .................................................................. 87
§10.2 多进程处理 ...................................................................... 93
§10.2.1 进程创建 .................................................................. 94
基本 I/O 操作 ................................................................. 95
§11.1 使用 Kernel 模块处理 I/O 操作 ...................................................... 95
§11.2 文件处理 ......................................................................... 95
§11.3 StringIO ......................................................................... 96
§11.4 Socket ........................................................................... 97
第十二章 反射和对象空间 ...................................................... 98
§12.1 ObjectSpace 模块 ................................................................ 98
§12.2 察看类和对象的状态 .............................................................. 99
§12.3 动态方法调用 ................................................................... 102
§12.3.1 使用 send 方法 ............................................................ 102
§12.3.2 使用 Method 类和 UnboundMethod 类 .......................................... 103
§12.3.3 使用 eval 方法 ............................................................ 104
§12.3.4 性能 ..................................................................... 105
§12.4 Hook 和回调方法 ................................................................ 106
§12.4.1 什么是 Hook .............................................................. 106
§12.4.2 Ruby 中的 Hook ............................................................ 106
§11.4.2 回调方法 ................................................................. 107
§12.5 跟踪程序的运行 ................................................................. 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 二进制数据保存 ........................................................... 110
§13.2.2 YAML 数据保存 ............................................................ 111
§13.3 定制序列化 ..................................................................... 112
§13.3.1 二进制数据保存 ........................................................... 112
§13.3.2 YAML 数据保存 ............................................................ 113
§13.3 YAML ........................................................................... 114
§13.3.1 集合类型 ................................................................. 115
§13.3.2 单行集合类型 ............................................................. 118
§13.3.3 基本类型 ................................................................. 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 级 ........................................................................... 121
§14.1 1 级 ........................................................................... 121
§14.2 2 级 ........................................................................... 121
5
§14.3 3 级 ........................................................................... 121
§14.4 4 级 ........................................................................... 121
第十五章 单元测试 ........................................................... 122
§15.1 什么是单元测试 ................................................................. 122
§15.2 Ruby 单元测试框架 .............................................................. 122
第二部分 内置类与模块 ...................................................... 122
第一章 内置类 ............................................................... 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
第二章 内置模块 ............................................................. 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 语言总结 ..................................................... 130
附录 134
§1 术语对照 .......................................................................... 134
Ruby语法基础教程内容截图
- PC官方版
- 安卓官方手机版
- IOS官方手机版