swifty_enum 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -4
- data/lib/swifty_enum.rb +2 -2
- data/lib/swifty_enum/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: 49b24144b99a4bfd84dfd0c01e5ab3a9dee0f33e
|
4
|
+
data.tar.gz: 40c17d11ed032c8c890588e1d118d73b3a1d954f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6414e553b226227623964baac4409efdde00682f93673746f37f8565d54d00c6840df6361f854deda7ffb51f511438c93332322a836445462cf1437667ad842c
|
7
|
+
data.tar.gz: 92fe919c450f04248908f856d3d96df3155111d82a2415e2c2b26e8e5ed70852d0a8a785c07d1f40b89cf5067258c11fa456db9c4ddb4e49342b8fb6b55a55a8
|
data/README.md
CHANGED
@@ -37,13 +37,13 @@ class Flag
|
|
37
37
|
|
38
38
|
# Now you can define enum case by 'def_case' statement.
|
39
39
|
# Usage: def_case CASE_NAME [RAWVALUE]
|
40
|
-
def_case
|
41
|
-
def_case
|
40
|
+
def_case :On, '1'
|
41
|
+
def_case :Off, '0'
|
42
42
|
|
43
|
-
# You can
|
43
|
+
# You can define method for each enum cases by 'def_method' statement.
|
44
44
|
# Please put this statement below all of 'def_case' statements.
|
45
45
|
# Usage: def_method METHOD_NAME { || ... }
|
46
|
-
def_method
|
46
|
+
def_method :status do |enum_case|
|
47
47
|
case enum_case
|
48
48
|
when On then
|
49
49
|
# You can't use return statement, but value of last statement is returned from enum method.
|
@@ -52,6 +52,16 @@ class Flag
|
|
52
52
|
'NG'
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
# You can also define method with variable arguments.
|
57
|
+
def_method :status_with do |enum_case, args|
|
58
|
+
if args.empty?
|
59
|
+
enum_case.status
|
60
|
+
else
|
61
|
+
about = args.join(', ')
|
62
|
+
"#{enum_case.status} with #{about}"
|
63
|
+
end
|
64
|
+
end
|
55
65
|
end
|
56
66
|
|
57
67
|
|
@@ -88,6 +98,7 @@ end
|
|
88
98
|
# Enum method is defined in each enum cases.
|
89
99
|
Flag::On.status # => 'OK'
|
90
100
|
Flag::Off.status # => 'NG'
|
101
|
+
Flag::On.status_with('foo') # => 'OK with foo'
|
91
102
|
|
92
103
|
# When you want to get all of enum cases, use 'enum_cases'.
|
93
104
|
Flag.enum_cases # => [Flag::On, Flag::Off]
|
data/lib/swifty_enum.rb
CHANGED
data/lib/swifty_enum/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swifty_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zeero
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|