funtools 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/funtools/pattern-matching.rb +11 -3
- data/lib/funtools/recursion.rb +5 -1
- data/lib/funtools.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 147a7fd803443d3bc56481e35023bfe25a9c6510
|
4
|
+
data.tar.gz: 81b7a9752e0bc7af02b4a713e77fa0b88afa67e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7991f402cc958d2872f038e2d48ad180224771a5488a7500744b97955b5a7db227f3b6d306bc6f13eb267391e84f6fb64ddd89ef4a8c791a2fd7bf5c1dc2b046
|
7
|
+
data.tar.gz: b372da0baad485064622feceb0fecccae595a8b2273a6f20beadb61816055e7fc0daac467a0eba2577a12b7bf7ebd2f7a9a2d06aade9cc1325787ba9c856f1fd
|
@@ -7,6 +7,7 @@ class Object
|
|
7
7
|
#
|
8
8
|
# Returns nothing.
|
9
9
|
def defpattern(sym)
|
10
|
+
old_method = self.class.method(sym) if self.class.method_defined?(:sym)
|
10
11
|
patterns = []
|
11
12
|
self.class.send(:define_method, sym) do |*l, &b|
|
12
13
|
patterns << ->(*n) do
|
@@ -16,7 +17,7 @@ class Object
|
|
16
17
|
if flat_m.length == flat_n.length
|
17
18
|
e = flat_m.zip(n.flatten)
|
18
19
|
unless e.reject { |e| e[0].nil? || e[0]==e[1] }.any?
|
19
|
-
|
20
|
+
instance_exec(*flat_n, &b)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end.(l.flatten)
|
@@ -25,13 +26,20 @@ class Object
|
|
25
26
|
|
26
27
|
yield
|
27
28
|
|
29
|
+
if old_method
|
30
|
+
self.class.send(:define_method, sym, &old_method)
|
31
|
+
else
|
32
|
+
self.class.send(:remove_method, sym)
|
33
|
+
end
|
34
|
+
|
28
35
|
message = :define_method if respond_to?(:define_method, true)
|
29
36
|
message ||= :define_singleton_method
|
30
37
|
self.send(message, sym) do |*args|
|
31
38
|
patterns.each do |pattern|
|
32
|
-
result = pattern
|
33
|
-
|
39
|
+
result = instance_exec(*args, &pattern)
|
40
|
+
return result unless result.nil?
|
34
41
|
end
|
42
|
+
nil
|
35
43
|
end
|
36
44
|
end
|
37
45
|
end
|
data/lib/funtools/recursion.rb
CHANGED
@@ -11,7 +11,11 @@ class Object
|
|
11
11
|
message ||= :define_singleton_method
|
12
12
|
self.send(message, sym) do |*n|
|
13
13
|
last = nil
|
14
|
-
[1].cycle.reduce(n)
|
14
|
+
[1].cycle.reduce(n) do |c, e|
|
15
|
+
break c if last == c
|
16
|
+
last = c
|
17
|
+
instance_exec(c, &block)
|
18
|
+
end
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
data/lib/funtools.rb
CHANGED
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.
|
4
|
+
version: 0.4.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-09-
|
11
|
+
date: 2014-09-14 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
|