modular_tree 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: 420d72c774f0602ebf2b50b7346ee64759aaf48f89b8e041c80fe76464dbd379
4
- data.tar.gz: 4ceb72733d99138a6244c4b163b46d0fb10fcdf20b8f7d61e582903bab750bc8
3
+ metadata.gz: a7ec15f5d6c64bba85a09321d1fcb7c1a22cd91fea24b1db49a2217a4dc73f08
4
+ data.tar.gz: '08cf720767c7c907e3b7d8007125fafe5a8b51abe8701d4d0a0c5d5736df5ccd'
5
5
  SHA512:
6
- metadata.gz: a5b2b90bcaaa71fd2754093cbd3ccca1fea3c9193c3261a82911bd10c7c8c6e74476804006238215aaf448062424dbfeef606550b69f378fd742d159d58b05b2
7
- data.tar.gz: 8330f74bf4368cc7d56f35b42e48ff4f1dd51641ed94f05f4340f222eef22d62d0a3b32c883e2e6d916b78762a3d23870e62131b3e2f461c10ccabf16070d6ce
6
+ metadata.gz: 171988f0d2150f15a555d035fa7833e53b64784fcbbf3a4d5c3c4dc7ab352ce3aa816dee8a281c802bb236f57951112e0c1b18e451ad62b001e26f66340c3beb
7
+ data.tar.gz: 23cefa409742a9926b83fb9f1f7aecdae78b78905d7ed765c1f4fdc0044730594d1ffda4ef806c513856b75ac40ba4d788f16c13312521d333d9a73ec0be036f
@@ -15,8 +15,6 @@
15
15
  #
16
16
  # Internal trees adds a parent/children relation
17
17
  #
18
- #
19
- #
20
18
  # Only internal trees have parent/child relations. External trees have only branch/branches relations
21
19
 
22
20
  module Tree
@@ -167,6 +165,12 @@ module Tree
167
165
 
168
166
  def each_child(&block) = @children.map(&block)
169
167
  def attach(child) = @children << child
168
+ def detach(arg)
169
+ key = arg.is_a?(Integer) ? arg : @children.index(arg)
170
+ child = @children.delete_at(key) or raise ArgumentError, "Can't find object"
171
+ child.send(:instance_variable_set, :@parent, nil)
172
+ child
173
+ end
170
174
 
171
175
  # Can be used with any array implementation. +where+ is either an Integer
172
176
  # index or an object
@@ -35,6 +35,12 @@ module Tree
35
35
  def children = abstract_method
36
36
  def each_child(&block) = children.each(&block)
37
37
  def attach(child) = abstract_method
38
+
39
+ # :call-seq:
40
+ # detach(key)
41
+ # detach(child)
42
+ #
43
+ def detach(arg) = abstract_method
38
44
  end
39
45
 
40
46
  # TODO
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tree
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modular_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen