sugar-high 0.4.5 → 0.4.5.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.5
1
+ 0.4.5.2
@@ -2,6 +2,25 @@ class Array
2
2
  def args
3
3
  flatten.map{|a| a.args}.flatten
4
4
  end
5
+
6
+ def last_option
7
+ default = self.last_arg
8
+ last = self.flatten.last
9
+ last.kind_of?(Hash) ? last : default
10
+ end
11
+
12
+ def last_arg default = {}
13
+ last = self.flatten.last
14
+ last.kind_of?(Hash) ? last : default
15
+ end
16
+
17
+ def last_arg_value default = nil
18
+ last = self.flatten.last
19
+ raise ArgumentError, "Default value must be a Hash, was #{default}" if !default.kind_of? Hash
20
+ key = default.keys.first
21
+ return default[key] if !last.kind_of? Hash
22
+ last[key] ? last[key] : default[key]
23
+ end
5
24
  end
6
25
 
7
26
  class Symbol
@@ -2,7 +2,13 @@ require 'sugar-high/kind_of'
2
2
  require 'sugar-high/enumerable'
3
3
  require 'sugar-high/path'
4
4
 
5
- class Array
5
+ class Array
6
+ def without(*values)
7
+ copy = self.dup
8
+ values.flatten.each { |value| copy.delete(value) }
9
+ copy
10
+ end
11
+
6
12
  def to_symbols
7
13
  res = self.flatten.select_labels
8
14
  res = res.map{|a| a.to_s.to_sym } if res
@@ -20,6 +20,42 @@ describe "SugarHigh" do
20
20
  it "should return arg list with 'hello', 'you'" do
21
21
  [:hello, ['you']].args.should == ['hello', 'you']
22
22
  end
23
+
24
+ describe '#last_arg' do
25
+ context 'Last arg with default hello' do
26
+ it "should return the default :hello" do
27
+ [3,4].last_arg(:hello).should == :hello
28
+ end
29
+
30
+ it "should return the :hello => 'abe' " do
31
+ [{:hi => :def}, 3, 4, :hi => 'abe'].last_arg.should == {:hi => 'abe'}
32
+ [{:hi => :def}, [3,4, :hi => 'abe']].last_arg.should == {:hi => 'abe'}
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#last_option' do
38
+ it "should return the last hash" do
39
+ [3,4, :x => 3, :y => 5].last_option.should == {:x => 3, :y => 5}
40
+ end
41
+ end
42
+
43
+ describe "Last argument value" do
44
+ context 'Last arg with default hello' do
45
+ it "should return the arg value 'abe' " do
46
+ [3,4, :hi => 'abe'].last_arg_value(:hi => :def).should == 'abe'
47
+ [[3,4, :hi => 'abe']].last_arg_value(:hi => :def).should == 'abe'
48
+ end
49
+
50
+ it "should return the arg value :def " do
51
+ [:hello => 'abe', :good => true].last_arg_value(:hi => :def).should == :def
52
+ end
53
+
54
+ it "should return the arg value :def " do
55
+ [3,4].last_arg_value(:hi => :def).should == :def
56
+ end
57
+ end
58
+ end
23
59
  end
24
60
 
25
61
  describe "Last argument" do
@@ -31,7 +67,7 @@ describe "SugarHigh" do
31
67
  it "should return the :hello => 'abe' " do
32
68
  last_arg({:hi => :def}, 3,4, :hi => 'abe').should == {:hi => 'abe'}
33
69
  last_arg({:hi => :def}, [3,4, :hi => 'abe']).should == {:hi => 'abe'}
34
- end
70
+ end
35
71
  end
36
72
  end
37
73
 
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.4.5"
8
+ s.version = "0.4.5.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Kristian Mandrup}]
12
- s.date = %q{2011-06-09}
12
+ s.date = %q{2011-06-11}
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugar-high
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-09 00:00:00.000000000Z
12
+ date: 2011-06-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2153304260 !ruby/object:Gem::Requirement
16
+ requirement: &2151903500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '2.5'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2153304260
24
+ version_requirements: *2151903500
25
25
  description: More Ruby sugar - inspired by the 'zuker' project
26
26
  email: kmandrup@gmail.com
27
27
  executables: []