ruby-enum 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/LICENSE.md +1 -1
- data/README.md +28 -3
- data/lib/ruby-enum/enum.rb +4 -13
- data/lib/ruby-enum/version.rb +1 -1
- data/pkg/ruby-enum-0.3.0.gem +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adefdfa7f7f41de28559b75eddd3a48d2fa624db
|
4
|
+
data.tar.gz: fff0f432422d79528e170105fd2650095980b90f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb221f6f89abf7b6e39239dbbcc1b99dbec7bf4f8913d02143fe9494c44503ffeea604fb746170bd619e62bb1195c9ba42fa5ce668af916d86818aa64901f365
|
7
|
+
data.tar.gz: ef9203ba82087347bfa97310ed4b6414abbd052cf9af40babd991078c1e523b074f400df8786ab63ed3e5390839e944be41a0274dbe44fc9a64012d8c80db4dd
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -27,7 +27,9 @@ Colors.values # [ "red", "green" ]
|
|
27
27
|
Colors.to_h # { :RED => "red", :GREEN => "green" }
|
28
28
|
```
|
29
29
|
|
30
|
-
###
|
30
|
+
### All `Enumerable` methods are supported.
|
31
|
+
|
32
|
+
#### Iterating
|
31
33
|
|
32
34
|
``` ruby
|
33
35
|
Colors.each do |key, enum|
|
@@ -36,7 +38,7 @@ Colors.each do |key, enum|
|
|
36
38
|
end
|
37
39
|
```
|
38
40
|
|
39
|
-
|
41
|
+
#### Mapping
|
40
42
|
|
41
43
|
``` ruby
|
42
44
|
Colors.map do |key, enum|
|
@@ -48,6 +50,29 @@ end
|
|
48
50
|
# => [ ['red', :RED], ['green', :GREEN] ]
|
49
51
|
```
|
50
52
|
|
53
|
+
#### Reducing
|
54
|
+
|
55
|
+
``` ruby
|
56
|
+
Colors.reduce([]) do |arr, (key, enum)|
|
57
|
+
# key and enum.key is :RED, :GREEN
|
58
|
+
# enum.value is "red", "green"
|
59
|
+
arr << [enum.value, key]
|
60
|
+
end
|
61
|
+
|
62
|
+
# => [ ['red', :RED], ['green', :GREEN] ]
|
63
|
+
```
|
64
|
+
|
65
|
+
#### Sorting
|
66
|
+
``` ruby
|
67
|
+
Colors.sort_by do |key, enum|
|
68
|
+
# key and enum.key is :RED, :GREEN
|
69
|
+
# enum.value is "red", "green"
|
70
|
+
enum.value
|
71
|
+
end
|
72
|
+
|
73
|
+
# => [ [:GREEN, #<Colors:...>], [:RED, #<Colors:...>] ]
|
74
|
+
```
|
75
|
+
|
51
76
|
## Contributing
|
52
77
|
|
53
78
|
You're encouraged to contribute to this gem.
|
@@ -59,6 +84,6 @@ You're encouraged to contribute to this gem.
|
|
59
84
|
|
60
85
|
## Copyright and License
|
61
86
|
|
62
|
-
Copyright (c) 2013, Daniel Doubrovkine and [Contributors](CHANGELOG.md).
|
87
|
+
Copyright (c) 2013-2014, Daniel Doubrovkine and [Contributors](CHANGELOG.md).
|
63
88
|
|
64
89
|
This project is licensed under the [MIT License](LICENSE.md).
|
data/lib/ruby-enum/enum.rb
CHANGED
@@ -8,6 +8,7 @@ module Ruby
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.included(base)
|
11
|
+
base.extend Enumerable
|
11
12
|
base.extend ClassMethods
|
12
13
|
end
|
13
14
|
|
@@ -31,19 +32,9 @@ module Ruby
|
|
31
32
|
end
|
32
33
|
|
33
34
|
# Iterate over all enumerated values.
|
34
|
-
#
|
35
|
-
def each(&
|
36
|
-
@_enum_hash.each
|
37
|
-
yield key, value
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Map all enumerated values.
|
42
|
-
# Yields a key and an enumerated instance.
|
43
|
-
def map(&_block)
|
44
|
-
@_enum_hash.map do |key, value|
|
45
|
-
yield key, value
|
46
|
-
end
|
35
|
+
# Required for Enumerable mixin
|
36
|
+
def each(&block)
|
37
|
+
@_enum_hash.each(&block)
|
47
38
|
end
|
48
39
|
|
49
40
|
# Attempt to parse an enumerated value.
|
data/lib/ruby-enum/version.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- lib/ruby-enum.rb
|
42
42
|
- lib/ruby_enum.rb
|
43
43
|
- LICENSE.md
|
44
|
+
- pkg/ruby-enum-0.3.0.gem
|
44
45
|
- Rakefile
|
45
46
|
- README.md
|
46
47
|
- ruby-enum.gemspec
|