case 0.2.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/case.rb +19 -4
- metadata +1 -1
data/Rakefile
CHANGED
data/lib/case.rb
CHANGED
@@ -26,12 +26,23 @@ class Any
|
|
26
26
|
@options = options
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
@options.
|
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
|
-
@
|
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
|
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]
|