defmatch 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/defmatch/version.rb +1 -1
- data/lib/defmatch.rb +2 -2
- data/spec/defmatch_spec.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 808ffbab0823cd56fcf58947e9a4069a9a0eaace
|
4
|
+
data.tar.gz: 24a6775f4a3104fd9e8eb11dccfac5994d32c38f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2f969d8e6555eeca144d12a147c78bdeb09032aecd05c18e4bcea029c548811836f881ead8e66a438d2f3db06eb7de557c2d6e38097e5f539debd3d6bb50da7
|
7
|
+
data.tar.gz: ec2832a06d1851b00105e4dbc52b4f09a66ea14942e42fc4f1c9e08d3d48fc9d56f9a910b01bcc2a362e0f4f3ae7177f21d84eeb40632170aa85f0e8d28d990c
|
data/README.md
CHANGED
@@ -45,7 +45,7 @@ x.times([1,2,3,4]) # -> [2,4,6,8]
|
|
45
45
|
```
|
46
46
|
|
47
47
|
## How does it work and how do I use it?
|
48
|
-
Defmatch is written as a module and when it's used to extend a class it creates a ```defmatch``` class method. The ```defmatch``` method takes one required argument as the name of the method you're defining. The remaining arguments are the pattern to match on when
|
48
|
+
Defmatch is written as a module and when it's used to extend a class it creates a ```defmatch``` class method. The ```defmatch``` method takes one required argument as the name of the method you're defining. The remaining arguments are the pattern to match on when calling that method. Those arguments can be classes, literals, or procedures (lambdas). It also requires a block which is the actual function body that will run when the pattern matches. Those with a java background will find this similar to method overloading, but more powerful. Those with an erlang background will feel right at home. Here are some concrete examples.
|
49
49
|
|
50
50
|
```ruby
|
51
51
|
class TestMe
|
data/lib/defmatch/version.rb
CHANGED
data/lib/defmatch.rb
CHANGED
@@ -13,7 +13,7 @@ module Defmatch
|
|
13
13
|
lambda do |*args|
|
14
14
|
test = true;
|
15
15
|
param_test_pairs = args.zip(tests)
|
16
|
-
param_test_pairs.each {|pair| if pair[1].call(pair[0]) == false; test = false; break; end; }
|
16
|
+
param_test_pairs.each {|pair| if (pair[1].nil? or (pair[1].call(pair[0]) == false)); test = false; break; end; }
|
17
17
|
return test
|
18
18
|
end
|
19
19
|
end
|
@@ -31,7 +31,7 @@ module Defmatch
|
|
31
31
|
return self.instance_exec(*args,&hash[:block])
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
raise ArgumentError, "No function clause matching arguments"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
data/spec/defmatch_spec.rb
CHANGED
@@ -46,6 +46,10 @@ describe Defmatch do
|
|
46
46
|
expect(instance.times("matchme")).to eq("matched literal matchme")
|
47
47
|
end
|
48
48
|
|
49
|
+
it 'should throw an argument error when arguments that don\'t match anything are given' do
|
50
|
+
expect { instance.times("will","break","this") }.to raise_error(ArgumentError)
|
51
|
+
end
|
52
|
+
|
49
53
|
end
|
50
54
|
|
51
55
|
end
|