lingohub_utils 1.0.3 → 1.0.5
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.
- data/lib/lh/core_extensions/array/raise_if_empty.rb +0 -2
- data/lib/lh/core_extensions/array/raise_if_item_nil.rb +0 -1
- data/lib/lh/core_extensions/array/to_h.rb +6 -2
- data/lib/lh/core_extensions/hash/raise_if_value_nil.rb +0 -1
- data/lib/lh/core_extensions/hash/raise_unless_has_key.rb +0 -1
- data/lib/lh/core_extensions/object/raise_if_nil.rb +0 -1
- data/lib/lh/core_extensions/struct/to_hash.rb +0 -1
- data/lib/lh/dependency_injection/autowire.rb +1 -2
- data/lib/lh/dependency_injection/context.rb +1 -1
- data/lib/lh/exceptions/base_error.rb +1 -2
- data/lib/lh/exceptions/general_exceptions.rb +2 -2
- data/lib/lingohub_utils/version.rb +1 -1
- data/spec/lh/core_extensions/array/raise_if_empty_spec.rb +0 -2
- data/spec/lh/core_extensions/array/raise_if_item_nil_spec.rb +0 -2
- data/spec/lh/core_extensions/array/to_h_spec.rb +6 -3
- data/spec/lh/core_extensions/hash/raise_if_value_nil_spec.rb +0 -2
- data/spec/lh/core_extensions/hash/raise_unless_has_key_spec.rb +0 -2
- data/spec/lh/core_extensions/object/raise_if_nil_spec.rb +0 -2
- metadata +3 -3
@@ -1,10 +1,14 @@
|
|
1
1
|
require "enumerator"
|
2
2
|
|
3
3
|
class Array
|
4
|
-
def to_h
|
4
|
+
def to_h(&block)
|
5
5
|
hash = Hash.new
|
6
6
|
self.each_with_index do |item, index|
|
7
|
-
|
7
|
+
if block_given?
|
8
|
+
hash[item] = yield(item)
|
9
|
+
else
|
10
|
+
hash[item] = index
|
11
|
+
end
|
8
12
|
end
|
9
13
|
hash
|
10
14
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
1
|
require "spec_helper"
|
4
2
|
|
5
3
|
describe Array do
|
@@ -16,6 +14,11 @@ describe Array do
|
|
16
14
|
['a', 'b', 'c'].to_h.should eql({'a' => 0, 'b' => 1, 'c' => 2})
|
17
15
|
end
|
18
16
|
end
|
19
|
-
end
|
20
17
|
|
18
|
+
context "using a block" do
|
19
|
+
it "should leave the item as key and the value passed thru the given block as value" do
|
20
|
+
['a', 'b', 'c'].to_h { |i| "#{i}!" }.should eql({'a' => 'a!', 'b' => 'b!', 'c' => 'c!'})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
21
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lingohub_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-11-30 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Util library used by lingohub
|
15
15
|
email:
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
68
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.8.
|
69
|
+
rubygems_version: 1.8.23
|
70
70
|
signing_key:
|
71
71
|
specification_version: 3
|
72
72
|
summary: This gem contains general util classes and extensions used by other lingohub
|