def_enum_helper 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/def_enum_helper.rb +34 -11
- data/lib/def_enum_helper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f228f2de771b59063b78d5cc48b4cd09d90fedd0
|
4
|
+
data.tar.gz: 9acd36ca28215033c92183105c6bf3f51d6a1bb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c84b07d8820b4956e3a01f67073ca35ddf2f46031a0b5ec87d348f4fcb1e4ad45b2c9a95e39a2576d80de37f991dc818219aa94fb45fdaf459ee5713fee151c
|
7
|
+
data.tar.gz: 0b1273f73956933aa6a4476cd8f69c3ca44ae4ff17f163d14c7219aabe86a96961ba8244b55bbd84132cbe9cea78499559bdfb4696532277531f2ffe8f87dc4c
|
data/lib/def_enum_helper.rb
CHANGED
@@ -1,20 +1,43 @@
|
|
1
1
|
require "def_enum_helper/version"
|
2
2
|
|
3
|
-
#
|
3
|
+
# Usage
|
4
|
+
|
5
|
+
# # 默认枚举从1开始递增
|
4
6
|
|
5
7
|
# def_enum :YinYang, {YANG: "阳", YIN: "阴"}
|
6
8
|
|
7
|
-
# puts YinYang::YANG
|
8
|
-
# puts YinYang::YIN
|
9
|
+
# puts YinYang::YANG # 1
|
10
|
+
# puts YinYang::YIN # 2
|
9
11
|
# y = YinYang[1]
|
10
|
-
# puts y.index #1
|
11
|
-
# puts y.display
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# YinYang.all
|
15
|
-
# puts YinYang.count #2
|
16
|
-
# YinYang.each{|x| puts x}
|
17
|
-
# puts
|
12
|
+
# puts y.index # 1
|
13
|
+
# puts y.display # 阳
|
14
|
+
# YinYang[:YANG] # same as YinYang[1]
|
15
|
+
# YinYang["阳"] # same as YinYang[1]
|
16
|
+
# YinYang.all # 所有枚举的struct array [#<struct index=1, display="阳">, # <struct index=2, display="阴">]
|
17
|
+
# puts YinYang.count # 2
|
18
|
+
# YinYang.each{|x| puts x} # <struct index=1, display="阳"> #<struct index=2, display="阴">
|
19
|
+
# puts YinYang.to_hash_array # [{:index=>1, :display=>"阳"}, {:index=>2, :display=>"阴"}]
|
20
|
+
# puts YingYang.to_json_array # [{"index":1,"display":"阳"},{"index":2,"display":"阴"}]
|
21
|
+
|
22
|
+
# # 自定义枚举整数值
|
23
|
+
|
24
|
+
# def_enum_with_index(:DataOperationType,
|
25
|
+
# [:INSERT, 3, '插入'],
|
26
|
+
# [:UPDATE, 4, '修改'],
|
27
|
+
# [:DELETE, 5, '删除'])
|
28
|
+
|
29
|
+
# puts DataOperationType::INSERT # 3
|
30
|
+
|
31
|
+
# # 自定义枚举对象
|
32
|
+
# CustomStruct = Struct.new(:index, :display, :short_name)
|
33
|
+
|
34
|
+
# def_enum_struct_with_index(:Country,
|
35
|
+
# {
|
36
|
+
# CHINA: CustomStruct.new(1, '中华人民共和国', '中国'),
|
37
|
+
# USA: CustomStruct.new(2, '美利坚合众国', '美国')
|
38
|
+
# })
|
39
|
+
|
40
|
+
# Country[:CHINA] # <struct CustomStruct index=1, display="中华人民共和国", short_name="中国">
|
18
41
|
|
19
42
|
DEFAULT_ENUM_BASE_INDEX = 1
|
20
43
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: def_enum_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Zhang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|