enums 0.0.1 → 1.0.0
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 +56 -2
- data/lib/enums/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f703a80394cb87387c0efe3311aed2c59220710
|
4
|
+
data.tar.gz: 39b065497a6e1fb107de0819e62999fc14c14fe0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 419c10d70475ab3b6800b6895dcb7eb2422f28c4284a27811c3ec0339922268c953e0a0844bb874a4554c5193f6d5b1b4e328cca9a129e82e694be73f6b69427
|
7
|
+
data.tar.gz: 3379a2c0395e83430e10b862f0de84cf5f4cc1fc2aebe5cbe5fd28e1e2eaf74c5a98a3b25b285cfdccc49841d69ad00d294e6f8d83c2c55fcc50595f6ab0e00b
|
data/README.md
CHANGED
@@ -6,7 +6,6 @@ enums library / gem - safe enumeration types - a set of symbolic keys bound to u
|
|
6
6
|
* bugs :: [github.com/s6ruby/enums/issues](https://github.com/s6ruby/enums/issues)
|
7
7
|
* gem :: [rubygems.org/gems/enums](https://rubygems.org/gems/enums)
|
8
8
|
* rdoc :: [rubydoc.info/gems/enums](http://rubydoc.info/gems/enums)
|
9
|
-
* forum :: [wwwmake](http://groups.google.com/group/wwwmake)
|
10
9
|
|
11
10
|
|
12
11
|
## Why `enums` in Ruby?
|
@@ -48,7 +47,7 @@ Why? Why not? Discuss.
|
|
48
47
|
Enum.new( 'Color', :red, :green, :blue )
|
49
48
|
```
|
50
49
|
|
51
|
-
(
|
50
|
+
(Auto-)builds a class and code like:
|
52
51
|
|
53
52
|
``` ruby
|
54
53
|
class Enum
|
@@ -122,6 +121,61 @@ color.is_a? Color #=> true
|
|
122
121
|
...
|
123
122
|
```
|
124
123
|
|
124
|
+
Let's try another example:
|
125
|
+
|
126
|
+
``` ruby
|
127
|
+
Enum.new( 'State', :fundraising, :expired_refund, :successful )
|
128
|
+
|
129
|
+
State.values #=> [0, 1, 2]
|
130
|
+
State.keys #=> [:fundraising, :expired_refund, :successful]
|
131
|
+
|
132
|
+
State.members #=> [FUNDRAISING, EXPIRED_REFUND, SUCCESSFUL]
|
133
|
+
# -or-
|
134
|
+
# [<State @key=:fundraising, @value=0>,
|
135
|
+
# <Safe @key=:expired_refund, @value=1>,
|
136
|
+
# <State @key=:successful, @value=2>]
|
137
|
+
State.members[0].key #=> :fundraising
|
138
|
+
State.members[0].value #=> 0
|
139
|
+
State.members[1].key #=> :expired_refund
|
140
|
+
State.members[1].value #=> 1
|
141
|
+
|
142
|
+
State.fundraising.value #=> 0
|
143
|
+
State.fundraising.key #=> :fundraising
|
144
|
+
State::FUNDRAISING.value #=> 0
|
145
|
+
State::FUNDRAISING.key #=> :fundraising
|
146
|
+
|
147
|
+
state = State.fundraising
|
148
|
+
state.fundraising? #=> true
|
149
|
+
state.value #=> 0
|
150
|
+
|
151
|
+
State(0) #=> State::FUNDRAISING
|
152
|
+
State(1) #=> State::EXPIRED_REFUND
|
153
|
+
State(2) #=> State::SUCCESSFUL
|
154
|
+
|
155
|
+
State.zero # same as State(0)
|
156
|
+
State(0) == State.zero #=> true
|
157
|
+
State(1) == State.zero #=> false
|
158
|
+
|
159
|
+
State.value(0) #=> State::FUNDRAISING
|
160
|
+
State[:fundraising] #=> State::FUNDRAISING
|
161
|
+
State.key(:fundraising) # same as State[:fundraising]
|
162
|
+
# ...
|
163
|
+
```
|
164
|
+
|
165
|
+
and so on.
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
## More "Real World" Enum Samples
|
170
|
+
|
171
|
+
- [The "Red Paper" about sruby](https://github.com/s6ruby/redpaper) - Small, Smart, Secure, Safe, Solid & Sound (S6) Ruby - The Ruby Programming Language for Contract / Transaction Scripts on the Blockchain World Computer - Yes, It's Just Ruby
|
172
|
+
- [Ruby Sample Contracts for the Universum Blockchain/World Computer Runtime](https://github.com/s6ruby/universum-contracts)
|
173
|
+
|
174
|
+
|
175
|
+
## More Safe Data Structure (Array, Hash, Struct)
|
176
|
+
|
177
|
+
[Safe Data Structures (Array, Hash, Struct)](https://github.com/s6ruby/safestruct) - Say goodbye to null / nil (and maybe) and the Billion-Dollar mistake. Say hello to zero and the Billon-Dollar fix.
|
178
|
+
|
125
179
|
|
126
180
|
|
127
181
|
## License
|
data/lib/enums/version.rb
CHANGED