case 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +2 -1
  2. data/lib/case.rb +24 -1
  3. data/test/test_case.rb +25 -0
  4. metadata +42 -34
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.4"
7
+ GEM_VERSION = "0.5"
8
8
 
9
9
  Rake::RDocTask.new do |task|
10
10
  task.rdoc_files.add [ 'lib/**/*.rb' ]
@@ -22,6 +22,7 @@ end
22
22
 
23
23
  gemspec = Gem::Specification.new do |gemspec|
24
24
  gemspec.name = "case"
25
+ gemspec.rubyforge_project = "concurrent"
25
26
  gemspec.version = GEM_VERSION
26
27
  gemspec.author = "MenTaLguY <mental@rydia.net>"
27
28
  gemspec.summary = "Pattern matching for Ruby"
@@ -7,7 +7,7 @@
7
7
 
8
8
  module Case
9
9
 
10
- module Impl
10
+ module Impl #:nodoc: all
11
11
  module Struct
12
12
  def ===(obj)
13
13
  return false unless self.class === obj
@@ -39,6 +39,20 @@ module Impl
39
39
  end
40
40
  end
41
41
 
42
+ class Not
43
+ class << self
44
+ alias_method :[], :new
45
+ end
46
+
47
+ def initialize(pattern)
48
+ @pattern = pattern
49
+ end
50
+
51
+ def ===(obj)
52
+ !( @pattern === obj )
53
+ end
54
+ end
55
+
42
56
  class Any < Impl::Operator
43
57
  def self.===(obj) ; true ; end
44
58
 
@@ -75,6 +89,15 @@ def self.guard(&predicate)
75
89
  Guard.new &predicate
76
90
  end
77
91
 
92
+ Cmp = Object.new
93
+ for op in %w(< > <= >=)
94
+ eval <<-EOS
95
+ def Cmp.#{op}(other)
96
+ Guard.new { |value| value #{op} other }
97
+ end
98
+ EOS
99
+ end
100
+
78
101
  # Shorthand for Case::Array.[]
79
102
  def self.[](*args)
80
103
  Array[*args]
@@ -10,5 +10,30 @@ class CaseTest < Test::Unit::TestCase
10
10
  assert !( c[1, 2, 3] === c[1, 2, Object] )
11
11
  end
12
12
  end
13
+
14
+ def test_array
15
+ [ ::Array, Case::Array ].each do |c|
16
+ assert c[1, 2, Object] === c[1, 2, 3]
17
+ assert !( c[1, 2, 3] === c[1, 2, Object] )
18
+ end
19
+ end
20
+
21
+ def test_cmp
22
+ assert (Case::Cmp > 0) === 1
23
+ assert !((Case::Cmp > 0) === 0)
24
+ assert (Case::Cmp < 0) === -1
25
+ assert !((Case::Cmp < 0) === 0)
26
+ assert (Case::Cmp <= 3) === 3
27
+ assert (Case::Cmp <= 3) === 2
28
+ assert !((Case::Cmp <= 3) === 4)
29
+ assert (Case::Cmp >= 3) === 3
30
+ assert (Case::Cmp >= 3) === 4
31
+ assert !((Case::Cmp >= 3) === 2)
32
+ end
33
+
34
+ def test_not
35
+ assert Case::Not['a'] === 'b'
36
+ assert !(Case::Not['a'] === 'a')
37
+ end
13
38
  end
14
39
 
metadata CHANGED
@@ -1,49 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
3
- specification_version: 1
4
2
  name: case
5
3
  version: !ruby/object:Gem::Version
6
- version: "0.4"
7
- date: 2008-01-22 00:00:00 -05:00
8
- summary: Pattern matching for Ruby
9
- require_paths:
10
- - lib
11
- email:
12
- homepage:
13
- rubyforge_project:
14
- description:
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: "0.5"
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
6
  authors:
29
7
  - MenTaLguY <mental@rydia.net>
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-13 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email:
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
30
24
  files:
31
25
  - Rakefile
32
- - test/test_all.rb
33
26
  - test/test_case.rb
27
+ - test/test_all.rb
34
28
  - lib/case.rb
35
29
  - lib/case/core.rb
36
- test_files:
37
- - test/test_all.rb
30
+ has_rdoc: true
31
+ homepage:
32
+ post_install_message:
38
33
  rdoc_options: []
39
34
 
40
- extra_rdoc_files: []
41
-
42
- executables: []
43
-
44
- extensions: []
45
-
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
46
49
  requirements: []
47
50
 
48
- dependencies: []
49
-
51
+ rubyforge_project: concurrent
52
+ rubygems_version: 1.1.1
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: Pattern matching for Ruby
56
+ test_files:
57
+ - test/test_all.rb