enumerable_hashify 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +11 -10
- data/enumerable_hashify.gemspec +3 -3
- data/lib/enumerable_hashify/enumerable.rb +10 -8
- data/lib/enumerable_hashify/version.rb +1 -1
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
= enumerable_hashify
|
2
2
|
|
3
3
|
Defines Enumerable#hashify, which creates a hash with the enumerable's
|
4
|
-
items as keys and with given constant value or with block-computed values:
|
4
|
+
items as keys and with a given constant value or with block-computed values:
|
5
5
|
|
6
|
-
[1,2,3,4].hashify
|
7
|
-
[1,2,3,4].hashify("a")
|
8
|
-
[1,2,3,4].hashify{|n| "a" * n}
|
6
|
+
[1,2,3,4].hashify --> {1=>true, 2=>true, 3=>true, 4=>true}
|
7
|
+
[1,2,3,4].hashify("a") --> {1=>"a", 2=>"a", 3=>"a", 4=>"a"}
|
8
|
+
[1,2,3,4].hashify{|n| "a" * n} --> {1=>"a", 2=>"aa", 3=>"aaa", 4=>"aaaa"}
|
9
9
|
|
10
10
|
== Tested on
|
11
11
|
|
@@ -18,11 +18,12 @@ Enumerable#to_h, and figured it was time to make a gem since nobody else
|
|
18
18
|
seems to have.
|
19
19
|
|
20
20
|
But there's been a bunch of discussion online as to what the proper
|
21
|
-
semantics that
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
semantics that Enumerable#to_h should have, without universal agreement. I
|
22
|
+
recently found a
|
23
|
+
proposal[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/11195]
|
24
|
+
from back in 2001 that suggested this same functionality with the name
|
25
|
+
Enumerable#hashify which seemed pretty good to me. I don't know why that
|
26
|
+
proposal wasn't adopted as part of ruby. But here it is as a gem.
|
26
27
|
|
27
28
|
== Note on Patches/Pull Requests
|
28
29
|
|
@@ -36,4 +37,4 @@ adopted as part of ruby. But here it is as a gem.
|
|
36
37
|
|
37
38
|
== Copyright
|
38
39
|
|
39
|
-
|
40
|
+
Released under the MIT License. See LICENSE for details.
|
data/enumerable_hashify.gemspec
CHANGED
@@ -5,12 +5,12 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.name = 'enumerable_hashify'
|
6
6
|
s.version = EnumerableHashify::VERSION
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.date =
|
8
|
+
s.date = "2011-06-08"
|
9
9
|
s.authors = ['Ronen Barzel']
|
10
10
|
s.email = 'ronen@barzel.org'
|
11
11
|
s.homepage = 'http://github.com/ronen/enumerable_hashify'
|
12
|
-
s.summary = %Q{Defines Enumerable#hashify}
|
13
|
-
s.description = %Q{Defines Enumerable#hashify, which creates a hash with the enumerable's
|
12
|
+
s.summary = %Q{Defines Enumerable#hashify, which creates a hash whose keys are the enumerable's elements, with given or computed values.}
|
13
|
+
s.description = %Q{Defines Enumerable#hashify, which creates a hash with the enumerable's elements as keys and with a given constant value or with block-computed values}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
'LICENSE',
|
16
16
|
'README.rdoc',
|
@@ -1,15 +1,17 @@
|
|
1
1
|
module Enumerable
|
2
|
-
#
|
3
|
-
#
|
2
|
+
# Create a hash whose keys are the enumerable's elements, with specified
|
3
|
+
# values.
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# If no block is given, the given parameter (default true) is used for
|
6
|
+
# all values, e.g.:
|
7
7
|
#
|
8
|
-
#
|
9
|
-
# a
|
10
|
-
# e.g.
|
8
|
+
# [1,2,3,4].hashify --> {1=>true, 2=>true, 3=>true, 4=>true}
|
9
|
+
# [1,2,3,4].hashify("a") --> {1=>"a", 2=>"a", 3=>"a", 4=>"a"}
|
11
10
|
#
|
12
|
-
#
|
11
|
+
# If a block is given, each key's value is the result of running the
|
12
|
+
# block for that key, e.g.:
|
13
|
+
#
|
14
|
+
# [1,2,3,4].hashify{|n| "a" * n} --> {1=>"a", 2=>"aa", 3=>"aaa", 4=>"aaaa"}
|
13
15
|
#
|
14
16
|
def hashify(val=true)
|
15
17
|
h = {}
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: enumerable_hashify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ronen Barzel
|
@@ -79,7 +79,7 @@ dependencies:
|
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: *id006
|
82
|
-
description: Defines Enumerable#hashify, which creates a hash with the enumerable's
|
82
|
+
description: Defines Enumerable#hashify, which creates a hash with the enumerable's elements as keys and with a given constant value or with block-computed values
|
83
83
|
email: ronen@barzel.org
|
84
84
|
executables: []
|
85
85
|
|
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
hash:
|
118
|
+
hash: 4062298202315961677
|
119
119
|
segments:
|
120
120
|
- 0
|
121
121
|
version: "0"
|
@@ -131,7 +131,7 @@ rubyforge_project:
|
|
131
131
|
rubygems_version: 1.6.2
|
132
132
|
signing_key:
|
133
133
|
specification_version: 3
|
134
|
-
summary: Defines Enumerable#hashify
|
134
|
+
summary: Defines Enumerable#hashify, which creates a hash whose keys are the enumerable's elements, with given or computed values.
|
135
135
|
test_files:
|
136
136
|
- spec/hashify_spec.rb
|
137
137
|
- spec/spec_helper.rb
|