enum_to_h 0.1.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 +7 -0
- data/lib/enum_to_h.rb +24 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75727f06222864f4a1b6f27be98bd3e0dc2b7378
|
4
|
+
data.tar.gz: b685ded5ef8ecf916316f14fb03c18b9fb442e54
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 58071b58ad2923e8e044f2ad8b3737a7a8ca5877b3a061e8933229ba22d2ff56753f91947ac600368e4eb23ee5be60008c42c1fbe4eb016bb2d4463cda726fa1
|
7
|
+
data.tar.gz: fe3c08a292d1cafb2f03fa431397886925765d23ce725c3d63437c3183a5012a16aac4f1a30a66412ef97c7c12f9efd9caf4f693e377859bb15fb9362a89878c
|
data/lib/enum_to_h.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
module Enumerable
|
3
|
+
#
|
4
|
+
# Converts +enum+ to a Hash.
|
5
|
+
#
|
6
|
+
# Each element of +enum+ must be a single item, or an array of two items.
|
7
|
+
# Duplicate keys are overwritten in order.
|
8
|
+
#
|
9
|
+
# [].to_h #=> {}
|
10
|
+
# [1,2].to_h #=> {1=>nil, 2=>nil}
|
11
|
+
# (1..2).to_h #=> {1=>nil, 2=>nil}
|
12
|
+
# [[1,2],[3,4]].to_h #=> {1=>2, 3=>4}
|
13
|
+
# [[1,2],[1,4]].to_h #=> {1=>4}
|
14
|
+
#
|
15
|
+
def to_h
|
16
|
+
hsh = {}
|
17
|
+
each do |k,v,*x|
|
18
|
+
raise ArgumentError, "invalid number of elements (#{x.length+1} for 1..2)" if x.any?
|
19
|
+
hsh[k] = v
|
20
|
+
end
|
21
|
+
hsh
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enum_to_h
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Kerwin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Defines Enumerable#to_h See https://bugs.ruby-lang.org/issues/7292
|
14
|
+
email: matthew@kerwin.net.au
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/enum_to_h.rb
|
20
|
+
homepage: http://rubygems.org/gems/enum_to_h
|
21
|
+
licenses:
|
22
|
+
- Simplified BSD License
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.0.0
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Enumerable#to_h
|
44
|
+
test_files: []
|