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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 050ab21f9d8461b8945a213a2f454fda069a44b2
4
- data.tar.gz: 21be01216d2b525b3451436bdd920170b3d51480
3
+ metadata.gz: 808ffbab0823cd56fcf58947e9a4069a9a0eaace
4
+ data.tar.gz: 24a6775f4a3104fd9e8eb11dccfac5994d32c38f
5
5
  SHA512:
6
- metadata.gz: c1bdc6c310cc0a49cb809d64ed77dfa9073ac55124e4b4adc365ec5608f222ffea9558c20ba40225552895e08a60f99064e1db9ecec8d1741be4014b23a6eff8
7
- data.tar.gz: 8f65bddf87a83e0bc890adac30dd073118de2bc66afebbb622b9ab506f4a3f54fef64cc243f22bb191936ca558949a3b9d10698086621e9f8668286fb848eb41
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 the method you're calling that method. Those arguments can be classes, literals, or procedures (lambdas). It also takes a block which is the actual function body that will run when the pattern matches. Those with a java background think method overloading, but more powerful. Those with an erlang background will feel right at home. But here are some concrete examples.
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
@@ -1,3 +1,3 @@
1
1
  module Defmatch
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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
- throw "No function clause matching arguments" #This should be a real Exception
34
+ raise ArgumentError, "No function clause matching arguments"
35
35
  end
36
36
  end
37
37
 
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defmatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Warnock