funtools 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 036d1878297cacd7200f654099de5562013960c0
4
- data.tar.gz: c9b7c2d23b5703886d1ed1259c48512d049e555c
3
+ metadata.gz: 2b4b981489c79e05b8c4a44d6f8afbff26dfc0e2
4
+ data.tar.gz: 465f3f22070619217d67a596f1cd2220f1d090be
5
5
  SHA512:
6
- metadata.gz: 1f6c44f96b373b4f0eab32e9a83c962d803172b81e4f4fa6e5a0eed4237ea2955ceb760d154b0fbda1e169c139b9de55f6f50f49ad8adb04d277d8f87e8b884d
7
- data.tar.gz: d72c6f65e29fe7342e20d47b1c1fb14ede77ad996d970af8ac6ab5b53caf5322e6dd386ae3f8727ebdca6923b967edd03c7571bd326f511c7028b733ed592047
6
+ metadata.gz: 5adbb472fd5108a306e5987f790dcd5425cb2803487bceccfff739f063126c3392d8c7e33ca53a99b364b93306fbe0a3802f719e0c271cd3e51958aad6d80070
7
+ data.tar.gz: 7550c3eaaa1c40fabe779e44b8c617faa444524701ec7ec82e62e8e4763fae055b889faeb9dd1b14718170e21c7d0b4e055888e78033385a072ffe9278a511d7
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ class Object
4
+ # Public: Define a method in the current scope which allow pattern matching
5
+ # function declaration to be used.
6
+ #
7
+ # sym - Symbol defining the name of the method to be created.
8
+ # block - Block containing the logic for the function to be created.
9
+ #
10
+ # Returns nothing.
11
+ def defpattern(sym)
12
+ patterns = []
13
+ self.class.send(:define_method, sym) do |*l, &b|
14
+ patterns << ->(*n) do
15
+ ->(*m) do
16
+ flat_m = m.flatten
17
+ flat_n = n.flatten
18
+ if flat_m.length == flat_n.length
19
+ e = flat_m.zip(n.flatten)
20
+ unless e.reject { |e| e[0].nil? || e[0]==e[1] }.any?
21
+ b.call(*flat_n)
22
+ end
23
+ end
24
+ end.(l.flatten)
25
+ end
26
+ end
27
+
28
+ yield
29
+
30
+ self.send(:define_method, sym) do |*args|
31
+ patterns.each do |pattern|
32
+ result = pattern[args]
33
+ break result unless result.nil?
34
+ end
35
+ end
36
+ end
37
+ end
data/lib/funtools.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Funtools
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tina Wuest
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-29 00:00:00.000000000 Z
11
+ date: 2014-09-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Tools to assist in programming in a more functional style
14
14
  email: tina@wuest.me
@@ -17,6 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/funtools.rb
20
+ - lib/funtools/pattern-matching.rb
20
21
  - lib/funtools/recursion.rb
21
22
  homepage: https://gitlab.com/wuest/funtools
22
23
  licenses: