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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e0ced60d6ed9e9fb379e0804f7483d97f8469b2
4
- data.tar.gz: 8a67751a1fd7777b39e5c1be070ab498875872a7
3
+ metadata.gz: adefdfa7f7f41de28559b75eddd3a48d2fa624db
4
+ data.tar.gz: fff0f432422d79528e170105fd2650095980b90f
5
5
  SHA512:
6
- metadata.gz: f4978a831b5fe81cf79abb6c1568b681e4750a8f6b50a904c32f5d5e9fe2dd7116e6935046f30956d241a93f53e462e20bf66be4fdb72f77ffe47d2773bf41c5
7
- data.tar.gz: 8f76f84efced4d354aa73bef8d3da875d2543cc4683bfe5db44adf23c1e748d62e5f5bdcfd0792e1e0b218f7f9c91a676782e9ff35dbb8b719c38df40c51d68c
6
+ metadata.gz: eb221f6f89abf7b6e39239dbbcc1b99dbec7bf4f8913d02143fe9494c44503ffeea604fb746170bd619e62bb1195c9ba42fa5ce668af916d86818aa64901f365
7
+ data.tar.gz: ef9203ba82087347bfa97310ed4b6414abbd052cf9af40babd991078c1e523b074f400df8786ab63ed3e5390839e944be41a0274dbe44fc9a64012d8c80db4dd
@@ -1,3 +1,7 @@
1
+ ### 0.4.0 (6/29/2014)
2
+
3
+ * Mixed in `Enumerable` - [@kgann](https://github.com/kgann).
4
+
1
5
  ### 0.3.0 (5/19/2014)
2
6
 
3
7
  * Added `Ruby::Enum#map` - [@ArnaudRinquin](https://github.com/ArnaudRinquin).
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-enum (0.3.0)
4
+ ruby-enum (0.4.0)
5
5
  i18n
6
6
 
7
7
  GEM
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2013 Daniel Doubrovkine.
3
+ Copyright (c) 2013-2014 Daniel Doubrovkine.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
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
- ### Iterating
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
- ### Mapping
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).
@@ -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
- # Yields a key and an enumerated instance.
35
- def each(&_block)
36
- @_enum_hash.each do |key, value|
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.
@@ -1,5 +1,5 @@
1
1
  module Ruby
2
2
  module Enum
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
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.3.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-05-19 00:00:00.000000000 Z
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