pattern-proc 0.0.6 → 0.0.7

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: 2e6e5c92ff2acd52f48ad6a3499622f6b6605ce3
4
- data.tar.gz: 48d17c98cf20548f02d4fb5a317c412235c22c3c
3
+ metadata.gz: e3db802617a6112ea03388bb5ed687030deaace5
4
+ data.tar.gz: 26a129d119fef62f511cc6182f87c6fa15b66d14
5
5
  SHA512:
6
- metadata.gz: 331e688e706805d3e03687107141f45b2652f8c0e568c02c79bdd3de0de7e7c0c78b4764708da4968d8215cdb288563f5a5d6ab13438e0315f82b3d59ce6bb4e
7
- data.tar.gz: acbdae026983fe1db56d77a1b88fd0aeca837980eb9637a5ccf421dcf03f2c1cf47b4ca26b92804959909838da7018f34bb60162f2fce614e3166d28da40aa4e
6
+ metadata.gz: 04f254c90a249e889c9a2e69111e668bb69253ab71abdb5bb3279f7e6df8b58d19d44ff353e9792ac0a270cb7b43bdcce4d633d7a4b6a002c195157c0753e68e
7
+ data.tar.gz: ae9b8b38c777eda4bd6608b512d11dd6976661a5ce02f262b58724ea1c78b9ff50185f1cf7d13051bf8f7dad156a64ae35b5a9efeb276c6b1bacc3d3814074c5
data/README.md CHANGED
@@ -2,3 +2,86 @@ pattern-proc
2
2
  ============
3
3
 
4
4
  pattern matching Proc definitions
5
+
6
+ pattern-proc is a Ruby gem designed to allow creation of pattern-matching procs in a repeated declaration mechanism similar to Haskell.
7
+
8
+ Usage:
9
+
10
+ require 'pattern-proc'
11
+
12
+ * manually instantiate a proc
13
+
14
+ cool_proc = PatternProc.new
15
+ cool_proc.with(5,10).returns(30)
16
+ cool_proc.with(3,70).returns(111)
17
+ cool_proc.with(3) do |second_arg|
18
+ second_arg * 10
19
+ end
20
+ cool_proc.with do |first_arg, second_arg| do
21
+ first_arg * second_arg
22
+ end
23
+
24
+ # later...
25
+
26
+ regular_proc = cool_proc.to_proc
27
+ regular_proc.(5,10)
28
+ \> 30
29
+ regular_proc.(3).(70)
30
+ \> 111
31
+ regular_proc.(3).(15)
32
+ \> 150 # second_arg * 10 case
33
+ regular_proc.(5,5)
34
+ \> 25 # first_arg * second_arg case
35
+
36
+ * declare methods in a class
37
+
38
+ class MyClass
39
+ include PatternProc::ClassMethods
40
+
41
+ pattern(:my_func).with(3,10).returns(30)
42
+ pattern(:my_func).with(4,11).returns(40)
43
+ end
44
+
45
+ # later...
46
+
47
+ obj = MyClass.new
48
+ obj.my_func(3,10)
49
+ \> 30
50
+ obj.my_func(4).(11)
51
+ \> 40
52
+
53
+ # or
54
+
55
+ class MySingletonClass
56
+ class << self
57
+ include PatternProc::ClassMethods
58
+ pattern(:my_class_func).with(:a, :b).returns(:c)
59
+ pattern(:my_class_func).with(:c) do |other|
60
+ other.to_s
61
+ end
62
+ end
63
+ end
64
+
65
+ * "mock" out Funkify-style partial application methods in tests
66
+
67
+ include PatternProc::TestMethods
68
+
69
+ describe 'something' do
70
+ it '"mocks" methods' do
71
+ mock_obj = mock 'anything'
72
+ mock_obj.pattern(:my_func).with(1,2).returns(10)
73
+ mock_obj.pattern(:my_func).with(1) do |x| x + 3 end
74
+
75
+ mock_obj.my_func(1).(2).should == 10
76
+ mock_obj.my_func(1,5).should == 8
77
+
78
+ SomeClass.pattern(:existing_func).with("hello").returns("goodbye")
79
+
80
+ SomeClass.exsting_func("hello").should == "goodbyes"
81
+ end
82
+ end
83
+
84
+ This gem was initially created to ease testing when using the Funkify gem, as is most clear in the last example. However I would like to build on this library and make the ClassMethods "DSL" more robust. Additionally, right now pattern matching is done by specificity rather than declaration order, and you can only define a proc implementation for the rightmost N arguments (as opposed to any set of arguments, eg.
85
+
86
+ do_stuff 5 x = x * 2
87
+ in Haskell). Finally I would like PatternProc to subclass Proc directly rather than requiring a call to to_proc.
@@ -0,0 +1 @@
1
+ require 'pattern_proc.rb'
data/pattern-proc.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'pattern-proc'
3
- s.version = '0.0.6'
3
+ s.version = '0.0.7'
4
4
  s.date = '2014-07-01'
5
5
  s.summary = 'Pattern Proc'
6
6
  s.description = 'define a Proc with pattern matching "re-declaration" ala Haskell'
@@ -1,4 +1,4 @@
1
- require 'pattern_proc'
1
+ require 'pattern-proc'
2
2
  include PatternProc::TestMethods
3
3
 
4
4
  class TestObjectClass
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pattern-proc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Pleasant-Ryan
@@ -21,6 +21,7 @@ files:
21
21
  - Gemfile.lock
22
22
  - LICENSE
23
23
  - README.md
24
+ - lib/pattern-proc.rb
24
25
  - lib/pattern-proc/class_methods.rb
25
26
  - lib/pattern-proc/object_methods.rb
26
27
  - lib/pattern-proc/pattern_proc.rb