ruby_peter_v 0.0.1 → 0.0.2

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/HISTORY.txt CHANGED
@@ -1,3 +1,7 @@
1
1
  0.0.1 (2012-12-20)
2
2
 
3
3
  * #single (self for nil; first for empty or 1 element; raise if size > 1)
4
+
5
+ 0.0.2 (2013-01-03)
6
+
7
+ * #single raises exception for nil (similar to #first)
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
@@ -1,11 +1,3 @@
1
- class NilClass
2
-
3
- def single
4
- self
5
- end
6
-
7
- end
8
-
9
1
  module Enumerable
10
2
 
11
3
  def single
@@ -1,3 +1,3 @@
1
1
  module RubyPeterV
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/spec/single_spec.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "single" do
4
- it "keeps a nil value" do
4
+ it "raises error on nil value (nil.first also raises error)" do
5
5
  a = nil
6
- a.single.should == nil
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 for > 1 element in set" do
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.1
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: 2012-12-20 00:00:00.000000000 Z
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec