assistance 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.1.1 (2008-01-18)
2
+
3
+ * Added Array#extract_options! method.
4
+
1
5
  === 0.1 (2008-01-14)
2
6
 
3
7
  * First "official" release.
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ include FileUtils
9
9
  # Configuration
10
10
  ##############################################################################
11
11
  NAME = "assistance"
12
- VERS = "0.1"
12
+ VERS = "0.1.1"
13
13
  CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
14
14
  RDOC_OPTS = [
15
15
  "--quiet",
@@ -0,0 +1,14 @@
1
+ # Array extensions
2
+ class Array
3
+ # Removes and returns the last member of the array if it is a hash. Otherwise,
4
+ # an empty hash is returned This method is useful when writing methods that
5
+ # take an options hash as the last parameter. For example:
6
+ #
7
+ # def validate_each(*args, &block)
8
+ # opts = args.extract_options!
9
+ # ...
10
+ # end
11
+ def extract_options!
12
+ last.is_a?(Hash) ? pop : {}
13
+ end
14
+ end
data/lib/assistance.rb CHANGED
@@ -5,4 +5,5 @@ dir = File.join(File.dirname(__FILE__), "assistance")
5
5
  connection_pool
6
6
  inflector
7
7
  blank
8
+ extract_options
8
9
  ].each {|f| require(File.join(dir, f))}
@@ -0,0 +1,25 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Array, "#extract_options!" do
4
+ specify "should return an empty hash for an empty array" do
5
+ [].extract_options!.should == {}
6
+ end
7
+
8
+ specify "should remove the last member and return it only if it's a hash" do
9
+ a = [1, 2, 3]
10
+ a.extract_options!.should == {}
11
+ a.should == [1, 2, 3]
12
+
13
+ a = [1, {1 => 2}, 3]
14
+ a.extract_options!.should == {}
15
+ a.should == [1, {1 => 2}, 3]
16
+
17
+ a = [1, {1 => 2}]
18
+ a.extract_options!.should == {1 => 2}
19
+ a.should == [1]
20
+
21
+ a = [{1 => 2}]
22
+ a.extract_options!.should == {1 => 2}
23
+ a.should == []
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assistance
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz, Sam Smoot, Sharon Rosner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-14 00:00:00 +02:00
12
+ date: 2008-01-18 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -30,6 +30,7 @@ files:
30
30
  - doc/rdoc
31
31
  - spec/blank_spec.rb
32
32
  - spec/connection_pool_spec.rb
33
+ - spec/extract_options.rb
33
34
  - spec/inflector_spec.rb
34
35
  - spec/rcov.opts
35
36
  - spec/spec.opts
@@ -39,6 +40,7 @@ files:
39
40
  - lib/assistance/blank.rb
40
41
  - lib/assistance/connection_pool.rb
41
42
  - lib/assistance/core_ext.rb
43
+ - lib/assistance/extract_options.rb
42
44
  - lib/assistance/inflections.rb
43
45
  - lib/assistance/inflector.rb
44
46
  - lib/assistance/time_calculations.rb