feldtruby 0.2.1 → 0.2.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.
@@ -31,4 +31,10 @@ class Array
31
31
  end
32
32
  res
33
33
  end
34
+
35
+ # Add an element unless it is already in the array
36
+ def add_unless_there(element)
37
+ self << element unless self.include?(element)
38
+ self
39
+ end
34
40
  end
data/lib/feldtruby.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # this is just for Hoe's version numbering
2
2
  class Feldtruby
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.2'
4
4
  end
5
5
  # This is the namespace under which we put things...
6
6
  module FeldtRuby; end
data/test/test_array.rb CHANGED
@@ -68,4 +68,18 @@ describe "Array extensions" do
68
68
  ]
69
69
  end
70
70
  end
71
- end
71
+
72
+ describe "add_unless_there" do
73
+ it "adds an element when array is empty" do
74
+ [].add_unless_there(1).must_equal [1]
75
+ end
76
+
77
+ it "adds an element when array is NOT empty" do
78
+ [1,2].add_unless_there(3).must_equal [1,2,3]
79
+ end
80
+
81
+ it "does nothing when element is already in array" do
82
+ [1,2,3].add_unless_there(3).must_equal [1,2,3]
83
+ end
84
+ end
85
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feldtruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: