contracts 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/contracts.rb +11 -16
  2. data/lib/foo.rb +4 -9
  3. metadata +3 -3
data/lib/contracts.rb CHANGED
@@ -2,12 +2,21 @@ require 'decorators'
2
2
  require 'builtin_contracts'
3
3
  module Contracts
4
4
  def self.included(base)
5
- base.extend MethodDecorators
5
+ common base
6
6
  end
7
7
 
8
8
  def self.extended(base)
9
- base.extend MethodDecorators
9
+ common base
10
10
  end
11
+
12
+ def self.common base
13
+ base.extend MethodDecorators
14
+ base.class_eval do
15
+ def Contract(*args)
16
+ self.class.Contract(*args)
17
+ end
18
+ end
19
+ end
11
20
  end
12
21
 
13
22
  # This is the main Contract class. When you write a new contract, you'll
@@ -206,17 +215,3 @@ class Contract < Decorator
206
215
  end
207
216
  end
208
217
  end
209
-
210
- # convenience function for small scripts.
211
- # Use as:
212
- #
213
- # use_contracts self
214
- #
215
- # And then you can use contracts on functions
216
- # that aren't in any module or class.
217
- def use_contracts(this)
218
- this.class.send(:include, Contracts)
219
- def this.Contract(*args)
220
- self.class.Contract(*args)
221
- end
222
- end
data/lib/foo.rb CHANGED
@@ -1,14 +1,9 @@
1
1
  require 'contracts'
2
- use_contracts(self)
2
+ include Contracts
3
3
 
4
- Contract Num, Num => Num
5
- def add x, y
6
- x + 1
7
- end
8
-
9
- Contract nil => Num
10
- def test
4
+ Contract Num => Num
5
+ def a(b)
11
6
  3
12
7
  end
13
8
 
14
- p test
9
+ p a("asd")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contracts
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 9
10
- version: 0.0.9
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aditya Bhargava