myrrha 3.0.0.rc2 → 3.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/myrrha/ext/domain.rb +9 -2
- data/lib/myrrha/version.rb +1 -1
- data/myrrha.noespec +1 -1
- data/spec/ext/domain/test_coerce.rb +7 -3
- metadata +1 -1
data/lib/myrrha/ext/domain.rb
CHANGED
@@ -13,10 +13,17 @@ module Domain
|
|
13
13
|
domain_error!(arg)
|
14
14
|
end
|
15
15
|
|
16
|
-
def [](first, *args)
|
17
|
-
|
16
|
+
def [](first = NOT_PROVIDED, *args)
|
17
|
+
if first == NOT_PROVIDED
|
18
|
+
coerce([])
|
19
|
+
elsif args.empty?
|
20
|
+
coerce(first)
|
21
|
+
else
|
22
|
+
coerce(args.unshift(first))
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
26
|
+
NOT_PROVIDED = Object.new
|
20
27
|
end # module CoercionMethods
|
21
28
|
include CoercionMethods
|
22
29
|
end # module Domain
|
data/lib/myrrha/version.rb
CHANGED
data/myrrha.noespec
CHANGED
@@ -7,8 +7,8 @@ describe Domain, "coerce" do
|
|
7
7
|
|
8
8
|
before do
|
9
9
|
domain.coercions do |c|
|
10
|
-
c.coercion(String){|v,_| expected
|
11
|
-
c.coercion(Array) {|v,_|
|
10
|
+
c.coercion(String){|v,_| expected }
|
11
|
+
c.coercion(Array) {|v,_| expected }
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -29,7 +29,11 @@ describe Domain, "coerce" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'supports Array literals' do
|
32
|
-
domain[1, 3].should eq(
|
32
|
+
domain[1, 3].should eq(expected)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'supports empty Array literals' do
|
36
|
+
domain[].should eq(expected)
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|