Ruby11 拾遗

AgendaLoopExpressionFile Read/WriteDebugProcess & ThreadLoopwhilea = 10while a > 0 puts a a -= 1enduntila = 100until a == 0 puts a a -= 1en


Ruby10 Class Module Gem 深入

Agendaclass_eval & instance_evalmethod_missingModule as a namespaceGemsrequire vs load$LOAD_PATHclass_eval首先class_eval是只有类才能调用的,Class#class_evalcl


Ruby9 Class & Modules 进阶

Ruby的内部类结构Array.class # => ClassClass.class # => Classsuperclass 查看父类Array.superclass # =>ObjectObject.superclass # =>BasicObjectBasicObje


Ruby8 继承(Inheritance)和模块(Modules)

继承示例# inheritanceclass User attr_accessor :name, :age def initialize name, age @name, @age = name, age end def panels # ||= 操作符, 如果变量不存在 那么就


Ruby7 OOP

Everything is Object 一切皆对象a = "hello"a.class # => Stringb = 3.14b.class # => Floatc = %w[pear cat horse]c.class # => ArrayInstance


Ruby6 细节补充

代码规范使用UTF-8编码使用空格缩进,不使用tab, 1 tab = 2 spaces不需要使用分号(;)和反斜杠()连接代码Demo# basic typesa = 1b = "hello world"# one linec = ["pear", &quo


Ruby5 其他的奇技淫巧

变量赋值# 变量交换a = 1b = 2b,a = a,bputs aputs bputs "-" * 30x = [1, 2, 3]a, b = x #默认会把数组中的值依次赋值给 a ,bputs aputs bputs "-" * 30x = [1, 2


Ruby4 Blocks and Exceptions

Block 代码块Block是一个参数匿名参数Callback使用do/en或者{}来定义{puts "hello"}Demo:# block usagedef hello puts "hello method start" yield yi


Ruby3 流程控制

if/else/elsifa = "hello"b = falseif a p aelsif b p belse p "ok"endunlessunless相当于if的反向断言unless false "ok"end


Ruby1 数据类型,变量

整数类型: 3,222小数: 3.14字符串: hello,world布尔类型: true(TrueClass),false(FalseClass)数组: [1,2],["hello","hello world"]Hash(字典): {"name&q