case 0.2.2 → 0.3

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.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/case.rb +19 -4
  3. metadata +1 -1
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake/rdoctask'
4
4
  require 'rake/gempackagetask'
5
5
  require 'rake/clean'
6
6
 
7
- GEM_VERSION = "0.2.2"
7
+ GEM_VERSION = "0.3"
8
8
 
9
9
  Rake::RDocTask.new do |task|
10
10
  task.rdoc_files.add [ 'lib/**/*.rb' ]
@@ -26,12 +26,23 @@ class Any
26
26
  @options = options
27
27
  end
28
28
 
29
- def options
30
- @options.dup
29
+ def ===(obj)
30
+ @options.any? { |e| e === obj }
31
+ end
32
+ end
33
+
34
+ # Pattern-matching conjunction
35
+ class All
36
+ class << self
37
+ alias_method :[], :new
38
+ end
39
+
40
+ def initialize(*patterns)
41
+ @patterns = patterns
31
42
  end
32
43
 
33
44
  def ===(obj)
34
- @options.any? { |e| e === obj }
45
+ @patterns.all? { |e| e === obj }
35
46
  end
36
47
  end
37
48
 
@@ -53,7 +64,7 @@ class Array < ::Array
53
64
  end
54
65
  end
55
66
 
56
- class Predicate
67
+ class Guard
57
68
  def initialize(&predicate)
58
69
  @predicate = predicate
59
70
  end
@@ -63,6 +74,10 @@ class Predicate
63
74
  end
64
75
  end
65
76
 
77
+ def self.guard(&predicate)
78
+ Guard.new &predicate
79
+ end
80
+
66
81
  # Shorthand for Case::Array.[]
67
82
  def self.[](*args)
68
83
  Array[*args]
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: case
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.2
6
+ version: "0.3"
7
7
  date: 2008-01-17 00:00:00 -05:00
8
8
  summary: Pattern matching for Ruby
9
9
  require_paths: