sugar-high 0.2.6 → 0.2.7
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/VERSION +1 -1
- data/lib/sugar-high/arguments.rb +15 -1
- data/spec/sugar-high/arguments_spec.rb +28 -0
- data/sugar-high.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.7
|
data/lib/sugar-high/arguments.rb
CHANGED
@@ -17,6 +17,20 @@ class String
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def last_option *args
|
20
|
+
default = last_arg({}, *args)
|
20
21
|
last = args.flatten.last
|
21
|
-
last.kind_of?(Hash) ? last :
|
22
|
+
last.kind_of?(Hash) ? last : default
|
23
|
+
end
|
24
|
+
|
25
|
+
def last_arg default, *args
|
26
|
+
last = args.flatten.last
|
27
|
+
last.kind_of?(Hash) ? last : default
|
28
|
+
end
|
29
|
+
|
30
|
+
def last_arg_value default, *args
|
31
|
+
last = args.flatten.last
|
32
|
+
raise ArgumentError, "Default value must be a Hash, was #{default}" if !default.kind_of? Hash
|
33
|
+
key = default.keys.first
|
34
|
+
return default[key] if !last.kind_of? Hash
|
35
|
+
last[key] ? last[key] : default[key]
|
22
36
|
end
|
@@ -22,6 +22,34 @@ describe "SugarHigh" do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
describe "Last argument" do
|
26
|
+
context 'Last arg with default hello' do
|
27
|
+
it "should return the default :hello" do
|
28
|
+
last_arg(:hello, 3,4).should == :hello
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return the :hello => 'abe' " do
|
32
|
+
last_arg({:hi => :def}, 3,4, :hi => 'abe').should == {:hi => 'abe'}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "Last argument value" do
|
38
|
+
context 'Last arg with default hello' do
|
39
|
+
it "should return the arg value 'abe' " do
|
40
|
+
last_arg_value({:hi => :def}, 3,4, :hi => 'abe').should == 'abe'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return the arg value :def " do
|
44
|
+
last_arg_value({:hi => :def}, :hello => 'abe', :good => true).should == :def
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return the arg value :def " do
|
48
|
+
last_arg_value({:hi => :def}, 3,4 ).should == :def
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
25
53
|
describe "Last option" do
|
26
54
|
context 'Last arg is Hash' do
|
27
55
|
it "should return the last hash" do
|
data/sugar-high.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sugar-high}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-15}
|
13
13
|
s.description = %q{More Ruby sugar - inspired by the 'zuker' project}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 7
|
9
|
+
version: 0.2.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-15 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|