case 0.5.1 → 0.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/README.rdoc +10 -10
- data/Rakefile +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -4,11 +4,11 @@ The case gem is a power-up for Ruby's case-matching.
|
|
4
4
|
|
5
5
|
== Structs
|
6
6
|
|
7
|
-
<code>Case::Struct</code> is a
|
8
|
-
class
|
9
|
-
<code>Struct</code> are matched, their fields
|
10
|
-
equality test. <code>Case::Struct</code>
|
11
|
-
<code>===</code> operator instead.
|
7
|
+
<code>Case::Struct</code> is a specialization of Ruby's standard
|
8
|
+
<code>Struct</code> class which supports structural matching. When two
|
9
|
+
instances of a normal Ruby <code>Struct</code> are matched, their fields
|
10
|
+
are compared using the normal equality test. <code>Case::Struct</code>
|
11
|
+
uses the case-matching <code>===</code> operator over each field instead.
|
12
12
|
|
13
13
|
Here's an example of some of the things which are possible:
|
14
14
|
|
@@ -161,13 +161,13 @@ The <, >, >= and <= operators are all supported.
|
|
161
161
|
|
162
162
|
== Guards
|
163
163
|
|
164
|
-
More general tests can be put in when statements using <code>Case
|
164
|
+
More general tests can be put in when statements using <code>Case.guard</code>.
|
165
165
|
|
166
166
|
require 'case'
|
167
167
|
|
168
168
|
["foobar", "beef", "lorem"].each do |value|
|
169
169
|
case value
|
170
|
-
when Case
|
170
|
+
when Case.guard { |v| v[1, 1] == "o" }
|
171
171
|
puts "second letter in #{value} is o"
|
172
172
|
else
|
173
173
|
puts "just got #{value}"
|
@@ -182,19 +182,19 @@ This will print:
|
|
182
182
|
|
183
183
|
(Yes, I realize a regular expression could be used for this purpose.)
|
184
184
|
|
185
|
-
In simple cases, when <code>Case
|
185
|
+
In simple cases, when <code>Case.guard</code> is being used directly, you
|
186
186
|
don't even need to bother with the block parameter:
|
187
187
|
|
188
188
|
["foobar", "beef", "lorem"].each do |value|
|
189
189
|
case value
|
190
|
-
when Case
|
190
|
+
when Case.guard { value[1, 1] == "o" }
|
191
191
|
puts "second letter in #{value} is o"
|
192
192
|
else
|
193
193
|
puts "just got #{value}"
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
|
-
(The parameter is really only there for when <code>Case
|
197
|
+
(The parameter is really only there for when <code>Case.guard</code> is
|
198
198
|
being used as part of a larger expression.)
|
199
199
|
|
200
200
|
== Negation
|
data/Rakefile
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: case
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MenTaLguY <mental@rydia.net>
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-12-
|
12
|
+
date: 2010-12-10 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|