option 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/option.rb +8 -0
- data/lib/option/version.rb +1 -1
- data/spec/option_spec.rb +15 -1
- metadata +4 -4
data/lib/option.rb
CHANGED
@@ -72,6 +72,10 @@ class SomeClass < OptionClass
|
|
72
72
|
!! blk.call(get)
|
73
73
|
end
|
74
74
|
|
75
|
+
def include?(value)
|
76
|
+
get == value
|
77
|
+
end
|
78
|
+
|
75
79
|
def filter(&blk)
|
76
80
|
exists?(&blk) ? self : None
|
77
81
|
end
|
@@ -139,6 +143,10 @@ class NoneClass < OptionClass
|
|
139
143
|
false
|
140
144
|
end
|
141
145
|
|
146
|
+
def include?(value)
|
147
|
+
false
|
148
|
+
end
|
149
|
+
|
142
150
|
def filter(&blk)
|
143
151
|
self
|
144
152
|
end
|
data/lib/option/version.rb
CHANGED
data/spec/option_spec.rb
CHANGED
@@ -45,6 +45,10 @@ describe NoneClass do
|
|
45
45
|
None.exists? {}.must_equal(false)
|
46
46
|
end
|
47
47
|
|
48
|
+
it "#include? should return false" do
|
49
|
+
None.include?(value).must_equal(false)
|
50
|
+
end
|
51
|
+
|
48
52
|
it "#fold should invoke the default proc" do
|
49
53
|
None.fold(proc { value }) { |v| v.to_f }.must_equal(value)
|
50
54
|
end
|
@@ -144,6 +148,14 @@ describe SomeClass do
|
|
144
148
|
Some(value).exists? { |v| v % 2 != 0 }.must_equal(false)
|
145
149
|
end
|
146
150
|
|
151
|
+
it "#include? should return true when the passed value and the boxed value are the same" do
|
152
|
+
Some(value).include?(value).must_equal(true)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "#include? should return false when the passed value and the boxed value are not the same" do
|
156
|
+
Some(value).include?(value + 1).must_equal(false)
|
157
|
+
end
|
158
|
+
|
147
159
|
it "#fold should map the proc over the value and return it" do
|
148
160
|
Some(value).fold(proc { value * 2 }) { |v| v * 3 }.must_equal(36)
|
149
161
|
end
|
@@ -171,7 +183,9 @@ describe SomeClass do
|
|
171
183
|
end
|
172
184
|
|
173
185
|
it "#flatten" do
|
174
|
-
Some(Some(Some(value))).flatten
|
186
|
+
inner_value = Some(Some(Some(value))).flatten
|
187
|
+
inner_value.must_be_some(value)
|
188
|
+
inner_value.or_nil.must_equal(value)
|
175
189
|
end
|
176
190
|
end
|
177
191
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: option
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
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
|
+
date: 2012-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
segments:
|
78
78
|
- 0
|
79
|
-
hash:
|
79
|
+
hash: 2753894737332832695
|
80
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
version: '0'
|
86
86
|
segments:
|
87
87
|
- 0
|
88
|
-
hash:
|
88
|
+
hash: 2753894737332832695
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project:
|
91
91
|
rubygems_version: 1.8.24
|