摘要: if/else/elsifa = 'hello'b = falseif a p aelsif b p belse p 'ok'endunlessunless相当于if的反向断言unless false 'ok'end# => 'ok'if/unlessa = 1 if a != 1 #如果a不是1 则a复制为1b = 2 unless defined?(b) #如果b未定义... 阅读全文
posted @ 2018-02-16 23:52 罗道义 阅读(161) 评论(0) 推荐(0) 编辑
摘要: Method(Function)def hi(name) p "hi " + nameendhi('666') # => "hi 666"hi 'code' #括号省略 => "hi code"def hello name p "hello #{name}"endhello 'world' # => "hello world"Method 参数def hi name='code' ... 阅读全文
posted @ 2018-02-16 23:37 罗道义 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 整数类型: 3,222小数: 3.14字符串: hello,world布尔类型: true(TrueClass),false(FalseClass)数组: [1,2],["hello","hello world"]Hash(字典): {"name"=>"luo","age"=>24},{:name=>"daoyi",:age=>24}Symbol(符号)::a,:hello,:"hello w... 阅读全文
posted @ 2018-02-16 21:54 罗道义 阅读(452) 评论(0) 推荐(0) 编辑
摘要: 继承子类从父类继承成员变量子类从父类继承成员函数#include "stdafx.h"class Person{public: int Age; int Sex; void Word() { printf("Person:Work"); }};class Teacher:public Person{public: int Level;};int m... 阅读全文
posted @ 2018-02-16 14:44 罗道义 阅读(431) 评论(0) 推荐(0) 编辑
摘要: 多态的实现原理#include "stdafx.h"#include #include class A{public: int x; virtual void Test() { printf("A \n"); }protected:private:};class B:public A{public: int x; void Test() { ... 阅读全文
posted @ 2018-02-16 14:43 罗道义 阅读(168) 评论(0) 推荐(0) 编辑
本站总访问量