tree_methods 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: aab96d2d92b494cfc332be9008d479d69b0d921f4ed3e62dbef96a6f48d10458
4
- data.tar.gz: 7e3d7e03769d31579017aa5863cfc56e2957c81e42dfb53f4c23b64004620dda
3
+ metadata.gz: 0ba0354c6ba024e1ed9768365b7a17484619ecdb5475f459c6c327a5a3f14dea
4
+ data.tar.gz: 0bd0d539df290319fc543ea89b11ae4a24dc084858317c39bc84e931c7993133
5
5
  SHA512:
6
- metadata.gz: fad481f6d603919461baefa1c150c15efb66289776381589f33dcf629b222d21d0c1ab1d44dc42eeb1c4510c5123ba05eb0ef4fb3103d8678a68fc0bee8936e2
7
- data.tar.gz: ff0df081b3eb0bfed369d3df96c691043aa4ece7a5a444fad6a7c4ad6a976209d92f623dc0dc69ac16d3103990364fd83122ce77e887fbaab4068dad5c84546e
6
+ metadata.gz: d20413db23e7d67403c886972699fab7ccbbb997c91dd227058fe899a06f289db1253c29035ab78eb6fa7df171d6278ecb57aa3a6e150b332b3d84c152c91460
7
+ data.tar.gz: bb56a86771cd117475864131c1ee73b4d09ea36f848d53d17696bbc3f2ac958bfbae0453f68b8b85266c7947d6d4b55a0be1659d71bf64c5700032d7d13996a7
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TreeMethods
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/tree_methods.rb CHANGED
@@ -1,18 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "tree_methods/version"
4
- require_relative "tree_methods/enumerable_tree_methods"
5
- require_relative "tree_methods/object_tree_methods"
6
4
 
7
5
  module TreeMethods
8
6
  class Error < StandardError; end
9
- end
10
7
 
11
- module Enumerable
12
- include EnumerableTreeMethods # FIXME
8
+ def follow(include_self = false, &block)
9
+ result = include_self ? [self] : []
10
+ follow_implementation(result, &block)
11
+ result
12
+ end
13
+
14
+ def preorder(include_self = true, &block)
15
+ result = include_self ? [self] : []
16
+ preorder_implementation(result, &block)
17
+ result
18
+ end
19
+
20
+ def postorder(include_self = true, &block)
21
+ result = []
22
+ postorder_implementation(result, &block)
23
+ include_self ? result + [self] : result
24
+ end
25
+
26
+ private
27
+ def follow_implementation(result, &block)
28
+ if follower = block.call(self)
29
+ result << follower
30
+ follower.send(:follow_implementation, result, &block)
31
+ end
32
+ end
33
+
34
+ def preorder_implementation(result, &block)
35
+ block.call(self).each { |node|
36
+ result << node
37
+ node.send(:preorder_implementation, result, &block)
38
+ }
39
+ end
40
+
41
+ def postorder_implementation(result, &block)
42
+ block.call(self).each { |node|
43
+ node.send(:postorder_implementation, result, &block)
44
+ result << node
45
+ }
46
+ end
13
47
  end
14
48
 
15
49
  class Object
16
- include ObjectTreeMethods # FIXME Whoa!
50
+ include TreeMethods # FIXME Whoa!
17
51
  end
18
52
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tree_methods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
@@ -23,8 +23,6 @@ files:
23
23
  - README.md
24
24
  - Rakefile
25
25
  - lib/tree_methods.rb
26
- - lib/tree_methods/enumerable_tree_methods.rb
27
- - lib/tree_methods/object_tree_methods.rb
28
26
  - lib/tree_methods/version.rb
29
27
  - sig/tree_methods.rbs
30
28
  homepage: http://www.nowhere.com/
@@ -1,32 +0,0 @@
1
- module EnumerableTreeMethods
2
- def preorder(include_self = true, &block)
3
- result = include_self ? [self] : []
4
- preorder_implementation(result, &block)
5
- result
6
- end
7
-
8
- def postorder(include_self = true, &block)
9
- result = []
10
- postorder_implementation(result, &block)
11
- include_self ? result + [self] : result
12
- end
13
-
14
- private
15
- def preorder_implementation(result, &block)
16
- block.call(self).each { |node|
17
- result << node
18
- node.send(:preorder_implementation, result, &block)
19
- }
20
- end
21
-
22
- def postorder_implementation(result, &block)
23
- block.call(self).each { |node|
24
- node.send(:postorder_implementation, result, &block)
25
- result << node
26
- }
27
- end
28
- end
29
-
30
-
31
-
32
-
@@ -1,16 +0,0 @@
1
- module ObjectTreeMethods
2
- def follow(include_self = false, &block)
3
- result = include_self ? [self] : []
4
- follow_implementation(result, &block)
5
- result
6
- end
7
-
8
- private
9
- def follow_implementation(result, &block)
10
- if follower = block.call(self)
11
- result << follower
12
- follower.send(:follow_implementation, result, &block)
13
- end
14
- end
15
- end
16
-