summaryrefslogtreecommitdiffhomepage
path: root/zh-cn
diff options
context:
space:
mode:
Diffstat (limited to 'zh-cn')
-rw-r--r--zh-cn/dart-cn.html.markdown499
-rwxr-xr-xzh-cn/git-cn.html.markdown2
-rwxr-xr-xzh-cn/python-cn.html.markdown475
-rw-r--r--zh-cn/ruby-cn.html.markdown330
4 files changed, 1305 insertions, 1 deletions
diff --git a/zh-cn/dart-cn.html.markdown b/zh-cn/dart-cn.html.markdown
new file mode 100644
index 00000000..1b0cceb9
--- /dev/null
+++ b/zh-cn/dart-cn.html.markdown
@@ -0,0 +1,499 @@
+---
+language: dart
+lang: zh-cn
+filename: learndart.dart
+contributors:
+ - ["Joao Pedrosa", "https://github.com/jpedrosa/"]
+translators:
+ - ["Guokai Han", "https://github.com/hanguokai/"]
+---
+
+Dart 是编程语言王国的新人。
+它借鉴了许多其他主流语言,并且不会偏离它的兄弟语言 JavaScript 太多。
+就像 JavaScript 一样,Dart 的目标是提供良好的浏览器集成。
+
+Dart 最有争议的特性必然是它的可选类型。
+
+```javascript
+import "dart:collection";
+import "dart:math" as DM;
+
+// 欢迎进入15分钟的 Dart 学习。 http://www.dartlang.org/
+// 这是一个可实际执行的向导。你可以用 Dart 运行它
+// 或者在线执行! 可以把代码复制/粘贴到这个网站。 http://try.dartlang.org/
+
+// 函数声明和方法声明看起来一样。
+// 函数声明可以嵌套。声明使用这种 name() {} 的形式,
+// 或者 name() => 单行表达式; 的形式。
+// 右箭头的声明形式会隐式地返回表达式的结果。
+example1() {
+ example1nested1() {
+ example1nested2() => print("Example1 nested 1 nested 2");
+ example1nested2();
+ }
+ example1nested1();
+}
+
+// 匿名函数没有函数名。
+example2() {
+ example2nested1(fn) {
+ fn();
+ }
+ example2nested1(() => print("Example2 nested 1"));
+}
+
+// 当声明函数类型的参数的时候,声明中可以包含
+// 函数参数需要的参数,指定所需的参数名即可。
+example3() {
+ example3nested1(fn(informSomething)) {
+ fn("Example3 nested 1");
+ }
+ example3planB(fn) { // 或者不声明函数参数的参数
+ fn("Example3 plan B");
+ }
+ example3nested1((s) => print(s));
+ example3planB((s) => print(s));
+}
+
+// 函数有可以访问到外层变量的闭包。
+var example4Something = "Example4 nested 1";
+example4() {
+ example4nested1(fn(informSomething)) {
+ fn(example4Something);
+ }
+ example4nested1((s) => print(s));
+}
+
+// 下面这个包含 sayIt 方法的类声明,同样有一个可以访问外层变量的闭包,
+// 就像前面的函数一样。
+var example5method = "Example5 sayIt";
+class Example5Class {
+ sayIt() {
+ print(example5method);
+ }
+}
+example5() {
+ // 创建一个 Example5Class 类的匿名实例,
+ // 并调用它的 sayIt 方法。
+ new Example5Class().sayIt();
+}
+
+// 类的声明使用这种形式 class name { [classBody] }.
+// classBody 中可以包含实例方法和变量,
+// 还可以包含类方法和变量。
+class Example6Class {
+ var example6InstanceVariable = "Example6 instance variable";
+ sayIt() {
+ print(example6InstanceVariable);
+ }
+}
+example6() {
+ new Example6Class().sayIt();
+}
+
+// 类方法和变量使用 static 关键词声明。
+class Example7Class {
+ static var example7ClassVariable = "Example7 class variable";
+ static sayItFromClass() {
+ print(example7ClassVariable);
+ }
+ sayItFromInstance() {
+ print(example7ClassVariable);
+ }
+}
+example7() {
+ Example7Class.sayItFromClass();
+ new Example7Class().sayItFromInstance();
+}
+
+// 字面量非常方便,但是对于在函数/方法的外层的字面量有一个限制,
+// 类的外层或外面的字面量必需是常量。
+// 字符串和数字默认是常量。
+// 但是 array 和 map 不是。他们需要用 "const" 声明为常量。
+var example8A = const ["Example8 const array"],
+ example8M = const {"someKey": "Example8 const map"};
+example8() {
+ print(example8A[0]);
+ print(example8M["someKey"]);
+}
+
+// Dart 中的循环使用标准的 for () {} 或 while () {} 的形式,
+// 以及更加现代的 for (.. in ..) {} 的形式, 或者
+// 以 forEach 开头并具有许多特性支持的函数回调的形式。
+var example9A = const ["a", "b"];
+example9() {
+ for (var i = 0; i < example9A.length; i++) {
+ print("Example9 for loop '${example9A[i]}'");
+ }
+ var i = 0;
+ while (i < example9A.length) {
+ print("Example9 while loop '${example9A[i]}'");
+ i++;
+ }
+ for (var e in example9A) {
+ print("Example9 for-in loop '${e}'");
+ }
+ example9A.forEach((e) => print("Example9 forEach loop '${e}'"));
+}
+
+// 遍历字符串中的每个字符或者提取其子串。
+var example10S = "ab";
+example10() {
+ for (var i = 0; i < example10S.length; i++) {
+ print("Example10 String character loop '${example10S[i]}'");
+ }
+ for (var i = 0; i < example10S.length; i++) {
+ print("Example10 substring loop '${example10S.substring(i, i + 1)}'");
+ }
+}
+
+// 支持两种数字格式 int 和 double 。
+example11() {
+ var i = 1 + 320, d = 3.2 + 0.01;
+ print("Example11 int ${i}");
+ print("Example11 double ${d}");
+}
+
+// DateTime 提供了日期/时间的算法。
+example12() {
+ var now = new DateTime.now();
+ print("Example12 now '${now}'");
+ now = now.add(new Duration(days: 1));
+ print("Example12 tomorrow '${now}'");
+}
+
+// 支持正则表达式。
+example13() {
+ var s1 = "some string", s2 = "some", re = new RegExp("^s.+?g\$");
+ match(s) {
+ if (re.hasMatch(s)) {
+ print("Example13 regexp matches '${s}'");
+ } else {
+ print("Example13 regexp doesn't match '${s}'");
+ }
+ }
+ match(s1);
+ match(s2);
+}
+
+// 布尔表达式必需被解析为 true 或 false,
+// 因为不支持隐式转换。
+example14() {
+ var v = true;
+ if (v) {
+ print("Example14 value is true");
+ }
+ v = null;
+ try {
+ if (v) {
+ // 不会执行
+ } else {
+ // 不会执行
+ }
+ } catch (e) {
+ print("Example14 null value causes an exception: '${e}'");
+ }
+}
+
+// try/catch/finally 和 throw 语句用于异常处理。
+// throw 语句可以使用任何对象作为参数。
+example15() {
+ try {
+ try {
+ throw "Some unexpected error.";
+ } catch (e) {
+ print("Example15 an exception: '${e}'");
+ throw e; // Re-throw
+ }
+ } catch (e) {
+ print("Example15 catch exception being re-thrown: '${e}'");
+ } finally {
+ print("Example15 Still run finally");
+ }
+}
+
+// 要想有效地动态创建长字符串,
+// 应该使用 StringBuffer。 或者 join 一个字符串的数组。
+example16() {
+ var sb = new StringBuffer(), a = ["a", "b", "c", "d"], e;
+ for (e in a) { sb.write(e); }
+ print("Example16 dynamic string created with "
+ "StringBuffer '${sb.toString()}'");
+ print("Example16 join string array '${a.join()}'");
+}
+
+// 字符串连接只需让相邻的字符串字面量挨着,
+// 不需要额外的操作符。
+example17() {
+ print("Example17 "
+ "concatenate "
+ "strings "
+ "just like that");
+}
+
+// 字符串使用单引号或双引号做分隔符,二者并没有实际的差异。
+// 这种灵活性可以很好地避免内容中需要转义分隔符的情况。
+// 例如,字符串内容里的 HTML 属性使用了双引号。
+example18() {
+ print('Example18 <a href="etc">'
+ "Don't can't I'm Etc"
+ '</a>');
+}
+
+// 用三个单引号或三个双引号表示的字符串
+// 可以跨越多行,并且包含行分隔符。
+example19() {
+ print('''Example19 <a href="etc">
+Example19 Don't can't I'm Etc
+Example19 </a>''');
+}
+
+// 字符串可以使用 $ 字符插入内容。
+// 使用 $ { [expression] } 的形式,表达式的值会被插入到字符串中。
+// $ 跟着一个变量名会插入变量的值。
+// 如果要在字符串中插入 $ ,可以使用 \$ 的转义形式代替。
+example20() {
+ var s1 = "'\${s}'", s2 = "'\$s'";
+ print("Example20 \$ interpolation ${s1} or $s2 works.");
+}
+
+// 可选类型允许作为 API 的标注,并且可以辅助 IDE,
+// 这样 IDE 可以更好地提供重构、自动完成和错误检测功能。
+// 目前为止我们还没有声明任何类型,并且程序运行地很好。
+// 事实上,类型在运行时会被忽略。
+// 类型甚至可以是错的,并且程序依然可以执行,
+// 好像和类型完全无关一样。
+// 有一个运行时参数可以让程序进入检查模式,它会在运行时检查类型错误。
+// 这在开发时很有用,但是由于增加了额外的检查会使程序变慢,
+// 因此应该避免在部署时使用。
+class Example21 {
+ List<String> _names;
+ Example21() {
+ _names = ["a", "b"];
+ }
+ List<String> get names => _names;
+ set names(List<String> list) {
+ _names = list;
+ }
+ int get length => _names.length;
+ void add(String name) {
+ _names.add(name);
+ }
+}
+void example21() {
+ Example21 o = new Example21();
+ o.add("c");
+ print("Example21 names '${o.names}' and length '${o.length}'");
+ o.names = ["d", "e"];
+ print("Example21 names '${o.names}' and length '${o.length}'");
+}
+
+// 类的继承形式是 class name extends AnotherClassName {} 。
+class Example22A {
+ var _name = "Some Name!";
+ get name => _name;
+}
+class Example22B extends Example22A {}
+example22() {
+ var o = new Example22B();
+ print("Example22 class inheritance '${o.name}'");
+}
+
+// 类也可以使用 mixin 的形式 :
+// class name extends SomeClass with AnotherClassName {}.
+// 必需继承某个类才能 mixin 另一个类。
+// 当前 mixin 的模板类不能有构造函数。
+// Mixin 主要是用来和辅助的类共享方法的,
+// 这样单一继承就不会影响代码复用。
+// Mixin 声明在类定义的 "with" 关键词后面。
+class Example23A {}
+class Example23Utils {
+ addTwo(n1, n2) {
+ return n1 + n2;
+ }
+}
+class Example23B extends Example23A with Example23Utils {
+ addThree(n1, n2, n3) {
+ return addTwo(n1, n2) + n3;
+ }
+}
+example23() {
+ var o = new Example23B(), r1 = o.addThree(1, 2, 3),
+ r2 = o.addTwo(1, 2);
+ print("Example23 addThree(1, 2, 3) results in '${r1}'");
+ print("Example23 addTwo(1, 2) results in '${r2}'");
+}
+
+// 类的构造函数名和类名相同,形式为
+// SomeClass() : super() {}, 其中 ": super()" 的部分是可选的,
+// 它用来传递参数给父类的构造函数。
+class Example24A {
+ var _value;
+ Example24A({value: "someValue"}) {
+ _value = value;
+ }
+ get value => _value;
+}
+class Example24B extends Example24A {
+ Example24B({value: "someOtherValue"}) : super(value: value);
+}
+example24() {
+ var o1 = new Example24B(),
+ o2 = new Example24B(value: "evenMore");
+ print("Example24 calling super during constructor '${o1.value}'");
+ print("Example24 calling super during constructor '${o2.value}'");
+}
+
+// 对于简单的类,有一种设置构造函数参数的快捷方式。
+// 只需要使用 this.parameterName 的前缀,
+// 它就会把参数设置为同名的实例变量。
+class Example25 {
+ var value, anotherValue;
+ Example25({this.value, this.anotherValue});
+}
+example25() {
+ var o = new Example25(value: "a", anotherValue: "b");
+ print("Example25 shortcut for constructor '${o.value}' and "
+ "'${o.anotherValue}'");
+}
+
+// 可以在大括号 {} 中声明命名参数。
+// 大括号 {} 中声明的参数的顺序是随意的。
+// 在中括号 [] 中声明的参数也是可选的。
+example26() {
+ var _name, _surname, _email;
+ setConfig1({name, surname}) {
+ _name = name;
+ _surname = surname;
+ }
+ setConfig2(name, [surname, email]) {
+ _name = name;
+ _surname = surname;
+ _email = email;
+ }
+ setConfig1(surname: "Doe", name: "John");
+ print("Example26 name '${_name}', surname '${_surname}', "
+ "email '${_email}'");
+ setConfig2("Mary", "Jane");
+ print("Example26 name '${_name}', surname '${_surname}', "
+ "email '${_email}'");
+}
+
+// 使用 final 声明的变量只能被设置一次。
+// 在类里面,final 实例变量可以通过常量的构造函数参数设置。
+class Example27 {
+ final color1, color2;
+ // 更灵活一点的方法是在冒号 : 后面设置 final 实例变量。
+ Example27({this.color1, color2}) : color2 = color2;
+}
+example27() {
+ final color = "orange", o = new Example27(color1: "lilac", color2: "white");
+ print("Example27 color is '${color}'");
+ print("Example27 color is '${o.color1}' and '${o.color2}'");
+}
+
+// 要导入一个库,使用 import "libraryPath" 的形式,或者如果要导入的是
+// 核心库使用 import "dart:libraryName" 。还有一个称为 "pub" 的包管理工具,
+// 它使用 import "package:packageName" 的约定形式。
+// 看下这个文件顶部的 import "dart:collection"; 语句。
+// 导入语句必需在其它代码声明之前出现。IterableBase 来自于 dart:collection 。
+class Example28 extends IterableBase {
+ var names;
+ Example28() {
+ names = ["a", "b"];
+ }
+ get iterator => names.iterator;
+}
+example28() {
+ var o = new Example28();
+ o.forEach((name) => print("Example28 '${name}'"));
+}
+
+// 对于控制流语句,我们有:
+// * 必需带 break 的标准 switch 语句
+// * if-else 和三元操作符 ..?..:..
+// * 闭包和匿名函数
+// * break, continue 和 return 语句
+example29() {
+ var v = true ? 30 : 60;
+ switch (v) {
+ case 30:
+ print("Example29 switch statement");
+ break;
+ }
+ if (v < 30) {
+ } else if (v > 30) {
+ } else {
+ print("Example29 if-else statement");
+ }
+ callItForMe(fn()) {
+ return fn();
+ }
+ rand() {
+ v = new DM.Random().nextInt(50);
+ return v;
+ }
+ while (true) {
+ print("Example29 callItForMe(rand) '${callItForMe(rand)}'");
+ if (v != 30) {
+ break;
+ } else {
+ continue;
+ }
+ // 不会到这里。
+ }
+}
+
+// 解析 int,把 double 转成 int,或者使用 ~/ 操作符在除法计算时仅保留整数位。
+// 让我们也来场猜数游戏吧。
+example30() {
+ var gn, tooHigh = false,
+ n, n2 = (2.0).toInt(), top = int.parse("123") ~/ n2, bottom = 0;
+ top = top ~/ 6;
+ gn = new DM.Random().nextInt(top + 1); // +1 because nextInt top is exclusive
+ print("Example30 Guess a number between 0 and ${top}");
+ guessNumber(i) {
+ if (n == gn) {
+ print("Example30 Guessed right! The number is ${gn}");
+ } else {
+ tooHigh = n > gn;
+ print("Example30 Number ${n} is too "
+ "${tooHigh ? 'high' : 'low'}. Try again");
+ }
+ return n == gn;
+ }
+ n = (top - bottom) ~/ 2;
+ while (!guessNumber(n)) {
+ if (tooHigh) {
+ top = n - 1;
+ } else {
+ bottom = n + 1;
+ }
+ n = bottom + ((top - bottom) ~/ 2);
+ }
+}
+
+// 程序的唯一入口点是 main 函数。
+// 在程序开始执行 main 函数之前,不期望执行任何外层代码。
+// 这样可以帮助程序更快地加载,甚至仅惰性加载程序启动时需要的部分。
+main() {
+ print("Learn Dart in 15 minutes!");
+ [example1, example2, example3, example4, example5, example6, example7,
+ example8, example9, example10, example11, example12, example13, example14,
+ example15, example16, example17, example18, example19, example20,
+ example21, example22, example23, example24, example25, example26,
+ example27, example28, example29, example30
+ ].forEach((ef) => ef());
+}
+
+```
+
+## 延伸阅读
+
+Dart 有一个综合性网站。它涵盖了 API 参考、入门向导、文章以及更多,
+还包括一个有用的在线试用 Dart 页面。
+http://www.dartlang.org/
+http://try.dartlang.org/
+
+
+
diff --git a/zh-cn/git-cn.html.markdown b/zh-cn/git-cn.html.markdown
index 7aab8986..8c24f0b8 100755
--- a/zh-cn/git-cn.html.markdown
+++ b/zh-cn/git-cn.html.markdown
@@ -120,7 +120,7 @@ $ git help
$ git help -a
# 在文档当中查找特定的命令
-$ git help <命令>
+# git help <命令>
$ git help add
$ git help commit
$ git help init
diff --git a/zh-cn/python-cn.html.markdown b/zh-cn/python-cn.html.markdown
new file mode 100755
index 00000000..259e4ed8
--- /dev/null
+++ b/zh-cn/python-cn.html.markdown
@@ -0,0 +1,475 @@
+---
+language: python
+contributors:
+ - ["Louie Dinh", "http://ldinh.ca"]
+translators:
+ - ["Chenbo Li", "http://binarythink.net"]
+filename: learnpython.py
+lang: zh-cn
+---
+
+Python 由 Guido Van Rossum 在90年代初创建。 它现在是最流行的语言之一
+我喜爱python是因为它有极为清晰的语法,甚至可以说,它就是可以执行的伪代码
+
+很欢迎来自您的反馈,你可以在[@louiedinh](http://twitter.com/louiedinh) 和 louiedinh [at] [google's email service] 这里找到我
+
+注意: 这篇文章针对的版本是Python 2.7,但大多也可使用于其他Python 2的版本
+如果是Python 3,请在网络上寻找其他教程
+
+```python
+# 单行注释
+""" 多行字符串可以用
+ 三个引号包裹,不过这也可以被当做
+ 多行注释
+"""
+
+####################################################
+## 1. 原始数据类型和操作符
+####################################################
+
+# 数字类型
+3 #=> 3
+
+# 简单的算数
+1 + 1 #=> 2
+8 - 1 #=> 7
+10 * 2 #=> 20
+35 / 5 #=> 7
+
+# 整数的除法会自动取整
+5 / 2 #=> 2
+
+# 要做精确的除法,我们需要引入浮点数
+2.0 # 浮点数
+11.0 / 4.0 #=> 2.75 好多了
+
+# 括号具有最高优先级
+(1 + 3) * 2 #=> 8
+
+# 布尔值也是原始数据类型
+True
+False
+
+# 用not来取非
+not True #=> False
+not False #=> True
+
+# 相等
+1 == 1 #=> True
+2 == 1 #=> False
+
+# 不等
+1 != 1 #=> False
+2 != 1 #=> True
+
+# 更多的比较操作符
+1 < 10 #=> True
+1 > 10 #=> False
+2 <= 2 #=> True
+2 >= 2 #=> True
+
+# 比较运算可以连起来写!
+1 < 2 < 3 #=> True
+2 < 3 < 2 #=> False
+
+# 字符串通过"或'括起来
+"This is a string."
+'This is also a string.'
+
+# 字符串通过加号拼接
+"Hello " + "world!" #=> "Hello world!"
+
+# 字符串可以被视为字符的列表
+"This is a string"[0] #=> 'T'
+
+# % 可以用来格式化字符串
+"%s can be %s" % ("strings", "interpolated")
+
+# 也可以用format方法来格式化字符串
+# 推荐使用这个方法
+"{0} can be {1}".format("strings", "formatted")
+# 也可以用变量名代替数字
+"{name} wants to eat {food}".format(name="Bob", food="lasagna")
+
+# None 是对象
+None #=> None
+
+# 不要用相等 `==` 符号来和None进行比较
+# 要用 `is`
+"etc" is None #=> False
+None is None #=> True
+
+# 'is' 可以用来比较对象的相等性
+# 这个操作符在比较原始数据时没多少用,但是比较对象时必不可少
+
+# None, 0, 和空字符串都被算作False
+# 其他的均为True
+0 == False #=> True
+"" == False #=> True
+
+
+####################################################
+## 2. 变量和集合
+####################################################
+
+# 很方便的输出
+print "I'm Python. Nice to meet you!"
+
+
+# 给变量赋值前不需要事先生命
+some_var = 5 # 规范用小写字母和下划线来做为变量名
+some_var #=> 5
+
+# 访问之前为赋值的变量会抛出异常
+# 查看控制流程一节来了解异常处理
+some_other_var # 抛出命名异常
+
+# if语句可以作为表达式来使用
+"yahoo!" if 3 > 2 else 2 #=> "yahoo!"
+
+# 列表用来保存序列
+li = []
+# 可以直接初始化列表
+other_li = [4, 5, 6]
+
+# 在列表末尾添加元素
+li.append(1) #li 现在是 [1]
+li.append(2) #li 现在是 [1, 2]
+li.append(4) #li 现在是 [1, 2, 4]
+li.append(3) #li 现在是 [1, 2, 4, 3]
+# 移除列表末尾元素
+li.pop() #=> 3 and li is now [1, 2, 4]
+# 放回来
+li.append(3) # li is now [1, 2, 4, 3] again.
+
+# 像其他语言访问数组一样访问列表
+li[0] #=> 1
+# 访问最后一个元素
+li[-1] #=> 3
+
+# 越界会抛出异常
+li[4] # 抛出越界异常
+
+# 切片语法需要用到列表的索引访问
+# 可以看做数学之中左闭右开区间
+li[1:3] #=> [2, 4]
+# 省略开头的元素
+li[2:] #=> [4, 3]
+# 省略末尾的元素
+li[:3] #=> [1, 2, 4]
+
+# 删除特定元素
+del li[2] # li 现在是 [1, 2, 3]
+
+# 合并列表
+li + other_li #=> [1, 2, 3, 4, 5, 6] - 不改变这两个列表
+
+# 通过拼接合并列表
+li.extend(other_li) # li 是 [1, 2, 3, 4, 5, 6]
+
+# 用in来返回元素是否在列表中
+1 in li #=> True
+
+# 返回列表长度
+len(li) #=> 6
+
+
+# 元组类似于列表,但是他是不可改变的
+tup = (1, 2, 3)
+tup[0] #=> 1
+tup[0] = 3 # 类型错误
+
+# 对于大多数的列表操作,也适用于元组
+len(tup) #=> 3
+tup + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6)
+tup[:2] #=> (1, 2)
+2 in tup #=> True
+
+# 你可以将元组解包赋给多个变量
+a, b, c = (1, 2, 3) # a是1,b是2,c是3
+# 如果不加括号,那么会自动视为元组
+d, e, f = 4, 5, 6
+# 现在我们可以看看交换两个数字是多么容易的事
+e, d = d, e # d是5,e是4
+
+
+# 字典用来储存映射关系
+empty_dict = {}
+# 字典初始化
+filled_dict = {"one": 1, "two": 2, "three": 3}
+
+# 字典也用中括号访问元素
+filled_dict["one"] #=> 1
+
+# 把所有的键保存在列表中
+filled_dict.keys() #=> ["three", "two", "one"]
+# 键的顺序并不是唯一的,得到的不一定是这个顺序
+
+# 把所有的值保存在列表中
+filled_dict.values() #=> [3, 2, 1]
+# 和键的顺序相同
+
+# 判断一个键是否存在
+"one" in filled_dict #=> True
+1 in filled_dict #=> False
+
+# 查询一个不存在的键会抛出键异常
+filled_dict["four"] # 键异常
+
+# 用get方法来避免键异常
+filled_dict.get("one") #=> 1
+filled_dict.get("four") #=> None
+# get方法支持在不存在的时候返回一个默认值
+filled_dict.get("one", 4) #=> 1
+filled_dict.get("four", 4) #=> 4
+
+# Setdefault是一个更安全的添加字典元素的方法
+filled_dict.setdefault("five", 5) #filled_dict["five"] 的值为 5
+filled_dict.setdefault("five", 6) #filled_dict["five"] 的值仍然是 5
+
+
+# 集合储存无顺序的元素
+empty_set = set()
+# 出事话一个集合
+some_set = set([1,2,2,3,4]) # filled_set 现在是 set([1, 2, 3, 4])
+
+# Python 2.7 之后,大括号可以用来表示集合
+filled_set = {1, 2, 2, 3, 4} # => {1 2 3 4}
+
+# 为集合添加元素
+filled_set.add(5) # filled_set 现在是 {1, 2, 3, 4, 5}
+
+# 用&来实现集合的交
+other_set = {3, 4, 5, 6}
+filled_set & other_set #=> {3, 4, 5}
+
+# 用|来实现集合的并
+filled_set | other_set #=> {1, 2, 3, 4, 5, 6}
+
+# 用-来实现集合的差
+{1,2,3,4} - {2,3,5} #=> {1, 4}
+
+# 用in来判断元素是否存在于集合中
+2 in filled_set #=> True
+10 in filled_set #=> False
+
+
+####################################################
+## 3. 控制流程
+####################################################
+
+# 新建一个变量
+some_var = 5
+
+# 这是个if语句,在python中缩进是很重要的。
+# 会输出 "some var is smaller than 10"
+if some_var > 10:
+ print "some_var is totally bigger than 10."
+elif some_var < 10: # 这个 elif 语句是不必须的
+ print "some_var is smaller than 10."
+else: # 也不是必须的
+ print "some_var is indeed 10."
+
+
+"""
+用for循环遍历列表
+输出:
+ dog is a mammal
+ cat is a mammal
+ mouse is a mammal
+"""
+for animal in ["dog", "cat", "mouse"]:
+ # 你可以用 % 来格式化字符串
+ print "%s is a mammal" % animal
+
+"""
+`range(number)` 返回从0到给定数字的列表
+输出:
+ 0
+ 1
+ 2
+ 3
+"""
+for i in range(4):
+ print i
+
+"""
+While循环
+输出:
+ 0
+ 1
+ 2
+ 3
+"""
+x = 0
+while x < 4:
+ print x
+ x += 1 # Shorthand for x = x + 1
+
+# 用 try/except块来处理异常
+
+# Python 2.6 及以上适用:
+try:
+ # 用raise来抛出异常
+ raise IndexError("This is an index error")
+except IndexError as e:
+ pass # Pass就是什么都不做,不过通常这里会做一些恢复工作
+
+
+####################################################
+## 4. 函数
+####################################################
+
+# 用def来新建函数
+def add(x, y):
+ print "x is %s and y is %s" % (x, y)
+ return x + y # Return values with a return statement
+
+# 调用带参数的函数
+add(5, 6) #=> 输出 "x is 5 and y is 6" 返回 11
+
+# 通过关键字赋值来调用函数
+add(y=6, x=5) # 顺序是无所谓的
+
+# 我们也可以定义接受多个变量的函数,这些变量是按照顺序排列的
+def varargs(*args):
+ return args
+
+varargs(1, 2, 3) #=> (1,2,3)
+
+
+# 我们也可以定义接受多个变量的函数,这些变量是按照关键字排列的
+def keyword_args(**kwargs):
+ return kwargs
+
+# 实际效果:
+keyword_args(big="foot", loch="ness") #=> {"big": "foot", "loch": "ness"}
+
+# 你也可以同时将一个函数定义成两种形式
+def all_the_args(*args, **kwargs):
+ print args
+ print kwargs
+"""
+all_the_args(1, 2, a=3, b=4) prints:
+ (1, 2)
+ {"a": 3, "b": 4}
+"""
+
+# 当调用函数的时候,我们也可以和之前所做的相反,把元组和字典展开为参数
+args = (1, 2, 3, 4)
+kwargs = {"a": 3, "b": 4}
+all_the_args(*args) # equivalent to foo(1, 2, 3, 4)
+all_the_args(**kwargs) # equivalent to foo(a=3, b=4)
+all_the_args(*args, **kwargs) # equivalent to foo(1, 2, 3, 4, a=3, b=4)
+
+# Python 有一等函数:
+def create_adder(x):
+ def adder(y):
+ return x + y
+ return adder
+
+add_10 = create_adder(10)
+add_10(3) #=> 13
+
+# 匿名函数
+(lambda x: x > 2)(3) #=> True
+
+# 内置高阶函数
+map(add_10, [1,2,3]) #=> [11, 12, 13]
+filter(lambda x: x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
+
+# 可以用列表方法来对高阶函数进行更巧妙的引用
+[add_10(i) for i in [1, 2, 3]] #=> [11, 12, 13]
+[x for x in [3, 4, 5, 6, 7] if x > 5] #=> [6, 7]
+
+####################################################
+## 5. 类
+####################################################
+
+# 我们新建的类是从object类中继承的
+class Human(object):
+
+ # 类属性,由所有类的对象共享
+ species = "H. sapiens"
+
+ # 基本构造函数
+ def __init__(self, name):
+ # 将参数赋给对象成员属性
+ self.name = name
+
+ # 成员方法,参数要有self
+ def say(self, msg):
+ return "%s: %s" % (self.name, msg)
+
+ # 类方法由所有类的对象共享
+ # 这类方法在调用时,会把类本身传给第一个参数
+ @classmethod
+ def get_species(cls):
+ return cls.species
+
+ # 静态方法是不需要类和对象的引用就可以调用的方法
+ @staticmethod
+ def grunt():
+ return "*grunt*"
+
+
+# 实例化一个类
+i = Human(name="Ian")
+print i.say("hi") # 输出 "Ian: hi"
+
+j = Human("Joel")
+print j.say("hello") # 输出 "Joel: hello"
+
+# 访问类的方法
+i.get_species() #=> "H. sapiens"
+
+# 改变共享属性
+Human.species = "H. neanderthalensis"
+i.get_species() #=> "H. neanderthalensis"
+j.get_species() #=> "H. neanderthalensis"
+
+# 访问静态变量
+Human.grunt() #=> "*grunt*"
+
+
+####################################################
+## 6. 模块
+####################################################
+
+# 我们可以导入其他模块
+import math
+print math.sqrt(16) #=> 4
+
+# 我们也可以从一个模块中特定的函数
+from math import ceil, floor
+print ceil(3.7) #=> 4.0
+print floor(3.7) #=> 3.0
+
+# 从模块中导入所有的函数
+# 警告:不推荐使用
+from math import *
+
+# 简写模块名
+import math as m
+math.sqrt(16) == m.sqrt(16) #=> True
+
+# Python的模块其实只是普通的python文件
+# 你也可以创建自己的模块,并且导入它们
+# 模块的名字就和文件的名字相同
+
+# 以可以通过下面的信息找找要成为模块需要什么属性或方法
+import math
+dir(math)
+
+
+```
+
+## 更多阅读
+
+希望学到更多?试试下面的链接:
+
+* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
+* [Dive Into Python](http://www.diveintopython.net/)
+* [The Official Docs](http://docs.python.org/2.6/)
+* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/)
+* [Python Module of the Week](http://pymotw.com/2/)
diff --git a/zh-cn/ruby-cn.html.markdown b/zh-cn/ruby-cn.html.markdown
new file mode 100644
index 00000000..16c0ed67
--- /dev/null
+++ b/zh-cn/ruby-cn.html.markdown
@@ -0,0 +1,330 @@
+---
+language: ruby
+filename: learnruby.rb
+lang: zh-cn
+contributors:
+ - ["David Underwood", "http://theflyingdeveloper.com"]
+ - ["Joel Walden", "http://joelwalden.net"]
+ - ["Luke Holder", "http://twitter.com/lukeholder"]
+translators:
+ - ["Lin Xiangyu", "https://github.com/oa414"]
+---
+
+```ruby
+# 这是单行注释
+
+=begin
+这是多行注释
+没人用这个
+你也不该用
+=end
+
+# 首先,也是最重要的,所有东西都是对象
+
+# 数字是对象
+
+3.class #=> Fixnum
+
+3.to_s #=> "3"
+
+
+# 一些基本的算术符号
+1 + 1 #=> 2
+8 - 1 #=> 7
+10 * 2 #=> 20
+35 / 5 #=> 7
+
+# 算术符号只是语法糖而已
+# 实际上是调用对象的方法
+1.+(3) #=> 4
+10.* 5 #=> 50
+
+# 特殊的只也是对象
+nil # 空
+true # 真
+false # 假
+
+nil.class #=> NilClass
+true.class #=> TrueClass
+false.class #=> FalseClass
+
+# 相等运算符
+1 == 1 #=> true
+2 == 1 #=> false
+
+# 不等运算符
+1 != 1 #=> false
+2 != 1 #=> true
+!true #=> false
+!false #=> true
+
+# 除了false自己,nil是唯一的值为false的对象
+
+!nil #=> true
+!false #=> true
+!0 #=> false
+
+# 更多比较
+1 < 10 #=> true
+1 > 10 #=> false
+2 <= 2 #=> true
+2 >= 2 #=> true
+
+# 字符串是对象
+
+'I am a string'.class #=> String
+"I am a string too".class #=> String
+
+placeholder = "use string interpolation"
+"I can #{placeholder} when using double quoted strings"
+#=> "I can use string interpolation when using double quoted strings"
+
+
+# 输出值
+puts "I'm printing!"
+
+# 变量
+x = 25 #=> 25
+x #=> 25
+
+# 注意赋值语句返回了赋的值
+# 这意味着你可以用多重赋值语句
+
+x = y = 10 #=> 10
+x #=> 10
+y #=> 10
+
+# 按照惯例,用snake_case 作为变量名
+snake_case = true
+
+# 使用具有描述性的运算符
+path_to_project_root = '/good/name/'
+path = '/bad/name/'
+
+# 符号(Symbols,也是对象)
+# 符号是不可变的,内部用整数类型表示的可重用的值。通常用它代替字符串来有效地表达有意义的值
+
+
+:pending.class #=> Symbol
+
+status = :pending
+
+status == :pending #=> true
+
+status == 'pending' #=> false
+
+status == :approved #=> false
+
+# 数组
+
+# 这是一个数组
+[1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5]
+
+# 数组可以包含不同类型的元素
+
+array = [1, "hello", false] #=> => [1, "hello", false]
+
+# 数组可以被索引
+# 从前面开始
+array[0] #=> 1
+array[12] #=> nil
+
+# 像运算符一样,[var]形式的访问
+# 也就是一个语法糖
+# 实际上是调用对象的[] 方法
+array.[] 0 #=> 1
+array.[] 12 #=> nil
+
+# 从尾部开始
+array[-1] #=> 5
+
+# 同时指定开始的位置和结束的位置
+array[2, 4] #=> [3, 4, 5]
+
+# 或者指定一个范围
+array[1..3] #=> [2, 3, 4]
+
+# 像这样往数组增加一个元素
+array << 6 #=> [1, 2, 3, 4, 5, 6]
+
+# 哈希表是Ruby的键值对的基本数据结构
+# 哈希表由大括号定义
+hash = {'color' => 'green', 'number' => 5}
+
+hash.keys #=> ['color', 'number']
+
+# 哈希表可以通过键快速地查询
+hash['color'] #=> 'green'
+hash['number'] #=> 5
+
+# 查询一个不存在地键将会返回nil
+hash['nothing here'] #=> nil
+
+# 用 #each 方法来枚举哈希表:
+hash.each do |k, v|
+ puts "#{k} is #{v}"
+end
+
+# 从Ruby 1.9开始, 用符号作为键的时候有特别的记号表示:
+
+new_hash = { defcon: 3, action: true}
+
+new_hash.keys #=> [:defcon, :action]
+
+# 小贴士:数组和哈希表都是可枚举的
+# 它们可以共享一些有用的方法,比如each, map, count, 和more
+
+# 控制流
+
+if true
+ "if statement"
+elsif false
+ "else if, optional"
+else
+ "else, also optional"
+end
+
+for counter in 1..5
+ puts "iteration #{counter}"
+end
+#=> iteration 1
+#=> iteration 2
+#=> iteration 3
+#=> iteration 4
+#=> iteration 5
+
+# 然而
+# 没人用for循环
+# 用`each`来代替,就像这样
+
+(1..5).each do |counter|
+ puts "iteration #{counter}"
+end
+#=> iteration 1
+#=> iteration 2
+#=> iteration 3
+#=> iteration 4
+#=> iteration 5
+
+counter = 1
+while counter <= 5 do
+ puts "iteration #{counter}"
+ counter += 1
+end
+#=> iteration 1
+#=> iteration 2
+#=> iteration 3
+#=> iteration 4
+#=> iteration 5
+
+grade = 'B'
+
+case grade
+when 'A'
+ puts "Way to go kiddo"
+when 'B'
+ puts "Better luck next time"
+when 'C'
+ puts "You can do better"
+when 'D'
+ puts "Scraping through"
+when 'F'
+ puts "You failed!"
+else
+ puts "Alternative grading system, eh?"
+end
+
+# 函数
+
+def double(x)
+ x * 2
+end
+
+# 函数 (以及所有的方法块) 隐式地返回了最后语句的值
+double(2) #=> 4
+
+# 当不存在歧义的时候括号是可有可无的
+double 3 #=> 6
+
+double double 3 #=> 12
+
+def sum(x,y)
+ x + y
+end
+
+# 方法的参数通过逗号分隔
+sum 3, 4 #=> 7
+
+sum sum(3,4), 5 #=> 12
+
+# yield
+# 所有的方法都有一个隐式的块参数
+# 可以用yield参数调用
+
+def surround
+ puts "{"
+ yield
+ puts "}"
+end
+
+surround { puts 'hello world' }
+
+# {
+# hello world
+# }
+
+
+# 用class关键字定义一个类
+class Human
+
+ # 一个类变量,它被这个类地所有实例变量共享
+ @@species = "H. sapiens"
+
+ # 构造函数
+ def initialize(name, age=0)
+ # 将参数name的值赋给实例变量@name
+ @name = name
+ # 如果没有给出age, 那么会采用参数列表中地默认地值
+ @age = age
+ end
+
+ # 基本的 setter 方法
+ def name=(name)
+ @name = name
+ end
+
+ # 基本地 getter 方法
+ def name
+ @name
+ end
+
+ # 一个类方法以self.开头
+ # 它可以被类调用,但不能被类的实例调用
+ def self.say(msg)
+ puts "#{msg}"
+ end
+
+ def species
+ @@species
+ end
+
+end
+
+
+# 类的例子
+jim = Human.new("Jim Halpert")
+
+dwight = Human.new("Dwight K. Schrute")
+
+# 让我们来调用一些方法
+jim.species #=> "H. sapiens"
+jim.name #=> "Jim Halpert"
+jim.name = "Jim Halpert II" #=> "Jim Halpert II"
+jim.name #=> "Jim Halpert II"
+dwight.species #=> "H. sapiens"
+dwight.name #=> "Dwight K. Schrute"
+
+# 调用对象的方法
+Human.say("Hi") #=> "Hi"
+
+```