ruby_peter_v 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.txt +4 -0
- data/README.md +7 -0
- data/lib/ruby_peter_v/single.rb +0 -8
- data/lib/ruby_peter_v/version.rb +1 -1
- data/spec/single_spec.rb +3 -3
- metadata +2 -2
data/HISTORY.txt
CHANGED
data/README.md
CHANGED
@@ -20,6 +20,13 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
* .single on enumerable (instead of unstable .first)
|
22
22
|
|
23
|
+
The background of this is that in many cases,
|
24
|
+
the developer knows there _should_ only be 1
|
25
|
+
element in the set. Using first is fine, but if
|
26
|
+
inadvertently more elements are present, the first
|
27
|
+
will happily choose a random entry (certainly with
|
28
|
+
ActiveRecord first) which is a silent bug.
|
29
|
+
|
23
30
|
## Contributing
|
24
31
|
|
25
32
|
1. Fork it
|
data/lib/ruby_peter_v/single.rb
CHANGED
data/lib/ruby_peter_v/version.rb
CHANGED
data/spec/single_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "single" do
|
4
|
-
it "
|
4
|
+
it "raises error on nil value (nil.first also raises error)" do
|
5
5
|
a = nil
|
6
|
-
a.single.should
|
6
|
+
lambda {a.single}.should raise_error
|
7
7
|
end
|
8
8
|
|
9
9
|
it "nil for empty set" do
|
@@ -16,7 +16,7 @@ describe "single" do
|
|
16
16
|
a.single.should == :a
|
17
17
|
end
|
18
18
|
|
19
|
-
it "exception for
|
19
|
+
it "exception for > 1 element in set" do
|
20
20
|
a = [:a, :b]
|
21
21
|
lambda{a.single}.should raise_exception
|
22
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_peter_v
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|