contracts 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/contracts.rb +2 -2
  2. data/lib/foo.rb +9 -4
  3. data/lib/test.rb +6 -5
  4. metadata +4 -4
data/lib/contracts.rb CHANGED
@@ -132,8 +132,8 @@ Contracts: #{@contracts.map { |t| t.is_a?(Class) ? t.name : t.class.name }.join(
132
132
  end
133
133
 
134
134
  def self.validate_hash(arg, contract)
135
- arg.keys.each do |k|
136
- result, info = validate(arg[k], contract[k])
135
+ contract.keys.each do |k|
136
+ result, info = valid?(arg[k], contract[k])
137
137
  return [result, info] unless result
138
138
  end
139
139
  end
data/lib/foo.rb CHANGED
@@ -1,6 +1,11 @@
1
- def foo(*args, kwargs)
2
- p args
3
- p kwargs
1
+ require 'contracts'
2
+ include Contracts
3
+
4
+ class Object
5
+ Contract Num, Num, Num
6
+ def add(a, b)
7
+ a + b
8
+ end
4
9
  end
5
10
 
6
- foo(1, 2, 3, :a => 1, :b => 2)
11
+ puts add(1, "foo")
data/lib/test.rb CHANGED
@@ -30,10 +30,11 @@ class Object
30
30
  acc + v
31
31
  end
32
32
  end
33
- end
34
33
 
35
- run {
36
- puts "hi!"
37
- }
34
+ Contract ({ :age => Num, :name => String }), nil
35
+ def person(data)
36
+ p data
37
+ end
38
+ end
38
39
 
39
- puts sum(1, 2, 3, 4)
40
+ person({:name => "Adit", :age => 25, :bar => 45})
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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aditya Bhargava
@@ -19,7 +19,7 @@ date: 2012-06-07 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: "This library provides contracts for Ruby. Contracts let you clearly \xE2\x80\x93 even beautifully \xE2\x80\x93 express how your code behaves, and free you from writing tons of boilerplate, defensive code."
22
+ description: This library provides contracts for Ruby. Contracts let you clearly express how your code behaves, and free you from writing tons of boilerplate, defensive code.
23
23
  email: bluemangroupie@gmail.com
24
24
  executables: []
25
25