Ruby11 拾遗
AgendaLoopExpressionFile Read/WriteDebugProcess & ThreadLoopwhilea = 10while a > 0 puts a a -= 1enduntila = 100until a == 0 puts a a -= 1en
AgendaLoopExpressionFile Read/WriteDebugProcess & ThreadLoopwhilea = 10while a > 0 puts a a -= 1enduntila = 100until a == 0 puts a a -= 1en
Agendaclass_eval & instance_evalmethod_missingModule as a namespaceGemsrequire vs load$LOAD_PATHclass_eval首先class_eval是只有类才能调用的,Class#class_evalcl
Ruby的内部类结构Array.class # => ClassClass.class # => Classsuperclass 查看父类Array.superclass # =>ObjectObject.superclass # =>BasicObjectBasicObje
继承示例# inheritanceclass User attr_accessor :name, :age def initialize name, age @name, @age = name, age end def panels # ||= 操作符, 如果变量不存在 那么就
Everything is Object 一切皆对象a = "hello"a.class # => Stringb = 3.14b.class # => Floatc = %w[pear cat horse]c.class # => ArrayInstance
代码规范使用UTF-8编码使用空格缩进,不使用tab, 1 tab = 2 spaces不需要使用分号(;)和反斜杠()连接代码Demo# basic typesa = 1b = "hello world"# one linec = ["pear", &quo
变量赋值# 变量交换a = 1b = 2b,a = a,bputs aputs bputs "-" * 30x = [1, 2, 3]a, b = x #默认会把数组中的值依次赋值给 a ,bputs aputs bputs "-" * 30x = [1, 2
Block 代码块Block是一个参数匿名参数Callback使用do/en或者{}来定义{puts "hello"}Demo:# block usagedef hello puts "hello method start" yield yi
if/else/elsifa = "hello"b = falseif a p aelsif b p belse p "ok"endunlessunless相当于if的反向断言unless false "ok"end
整数类型: 3,222小数: 3.14字符串: hello,world布尔类型: true(TrueClass),false(FalseClass)数组: [1,2],["hello","hello world"]Hash(字典): {"name&q