摘要: 模板下面是一个针对int的冒泡排序// _20180301.cpp : Defines the entry point for the console application.//#include "stdafx.h"void Sort(int* arr,int nLength){ int i,k; for (i = 0;iarr[k+1]) { ... 阅读全文
posted @ 2018-03-01 16:27 罗道义 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 深浅拷贝相同类型间可以直接拷贝// _20180212.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include class A{private: int* a;public: A() { a = new int[10]; }... 阅读全文
posted @ 2018-02-23 22:27 罗道义 阅读(238) 评论(0) 推荐(0) 编辑
摘要: AgendaLoopExpressionFile Read/WriteDebugProcess & ThreadLoopwhilea = 10while a > 0 puts a a -= 1enduntila = 100until a == 0 puts a a -= 1endloopa = 10loop do break if a 0!~ 正则匹配 是否匹配不到 匹配到返回fals... 阅读全文
posted @ 2018-02-21 00:20 罗道义 阅读(177) 评论(0) 推荐(0) 编辑
摘要: Agendaclass_eval & instance_evalmethod_missingModule as a namespaceGemsrequire vs load$LOAD_PATHclass_eval首先class_eval是只有类才能调用的,Class#class_evalclass_eval会重新打开当前类的作用域# class_evalclass UserendUser.clas... 阅读全文
posted @ 2018-02-20 22:24 罗道义 阅读(196) 评论(0) 推荐(0) 编辑
摘要: Ruby的内部类结构Array.class # => ClassClass.class # => Classsuperclass 查看父类Array.superclass # =>ObjectObject.superclass # =>BasicObjectBasicObject.superclass # => nilancestors 查看当前类的继承链Array.ancestors # => ... 阅读全文
posted @ 2018-02-18 21:28 罗道义 阅读(267) 评论(0) 推荐(0) 编辑
摘要: 继承示例# inheritanceclass User attr_accessor :name, :age def initialize name, age @name, @age = name, age end def panels # ||= 操作符, 如果变量不存在 那么就赋值 @panels ||= ['Profile', 'Products'] endendc... 阅读全文
posted @ 2018-02-18 03:13 罗道义 阅读(137) 评论(0) 推荐(0) 编辑
摘要: Everything is Object 一切皆对象a = "hello"a.class # => Stringb = 3.14b.class # => Floatc = %w[pear cat horse]c.class # => ArrayInstance Method & Instance Attribute 实例方法,实例属性Instance Method: 实例方法,成员方法,成员函数I... 阅读全文
posted @ 2018-02-17 21:00 罗道义 阅读(159) 评论(0) 推荐(0) 编辑
摘要: ## 代码规范1. 使用UTF-8编码2. 使用空格缩进,不使用tab, 1 tab = 2 spaces3. 不需要使用分号(;)和反斜杠(\)连接代码Demo```ruby# basic typesa = 1b = "hello world"# one linec = ["pear", "cat", "dog"]# or multiple linesc2 = [ "pear", "cat", ... 阅读全文
posted @ 2018-02-17 19:42 罗道义 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 变量赋值# 变量交换a = 1b = 2b,a = a,bputs aputs bputs '-' * 30x = [1, 2, 3]a, b = x #默认会把数组中的值依次赋值给 a ,bputs aputs bputs '-' * 30x = [1, 2, 3]a, *b = x #这里a会接受第一个元素 b用了*号 表示接受剩下所有的元素puts ap b#output21--------... 阅读全文
posted @ 2018-02-17 04:17 罗道义 阅读(198) 评论(0) 推荐(0) 编辑
摘要: Block 代码块Block是一个参数匿名参数Callback使用do/en或者{}来定义{puts 'hello'}Demo:# block usagedef hello puts 'hello method start' yield yield puts 'hello method end'endhello {puts 'i am in block'}#output h... 阅读全文
posted @ 2018-02-17 04:01 罗道义 阅读(142) 评论(0) 推荐(0) 编辑
本站总访问量