rooted_tree 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
  SHA1:
3
- metadata.gz: a23c9e6f541bfd82e32fa1417fefd88b8357e843
4
- data.tar.gz: 05ac69ac576ba55e81c05d064d1adaa73380a8e6
3
+ metadata.gz: 5fb0517447c09795b818f9918deab292ff76b693
4
+ data.tar.gz: 9828b9590b6a2e98df0d956e5c316bde85cc982b
5
5
  SHA512:
6
- metadata.gz: dcffedd7ac50e2220bdd1dd7e6dbc9158bda7144eaa79c60e5a3c39a15375e1e7a7b3e6b77a7d316d48c5c4b8115444e732f6f6659a7b6a304770e12596fc452
7
- data.tar.gz: e76035b943dabc64f8455d158f6d0074cbbb3605eb253646045e9538fba115c7321d961c7936e86e2d4bc48b4e6f51ef72d834aae2c332ffd82a22e7e181051f
6
+ metadata.gz: 2f4290bf9357d919e8d92da2724366a405080fddf4e91878b74849f003986de6eddc42a68bd8038fb57ce3afb5106eb23226d049a84f902e5f6b32d6d35e36ec
7
+ data.tar.gz: 4aaddad4f3f6f8c7f5a771889dae2a9ea5c3f4c6568a8500eb0a2f8f36fc1ee16c2f7d6d240ec117507ed40f1997ac30e1fb46c8069e995b70f27b809c8269d0
@@ -38,6 +38,11 @@ module RootedTree
38
38
  @first_child = duped_children.first
39
39
  @last_child = duped_children.last
40
40
  end
41
+
42
+ def freeze
43
+ super
44
+ children.each(&:freeze)
45
+ end
41
46
 
42
47
  # Leaf?
43
48
  #
@@ -351,13 +356,22 @@ module RootedTree
351
356
  children.to_a == other.children.to_a
352
357
  end
353
358
 
359
+ # Tree!
360
+ #
361
+ # Wraps the entire tree in a Tree object. The operation will freeze the node
362
+ # structure, making it immutable. If this node is a child the root will be
363
+ # found and passed to Tree.new.
364
+
365
+ def tree!
366
+ Tree.new root
367
+ end
368
+
354
369
  # Tree
355
370
  #
356
- # Wraps the entire tree in a Tree object If this node is a child the root
357
- # will be found and passed to Tree.new.
371
+ # Duplicates the entire tree and calls #tree! on the copy.
358
372
 
359
373
  def tree
360
- Tree.new root
374
+ root.dup.tree!
361
375
  end
362
376
 
363
377
  # Subtree!
@@ -2,8 +2,9 @@ module RootedTree
2
2
  class Tree
3
3
  attr_reader :root
4
4
 
5
- def initialize(node = Node.new)
5
+ def initialize(node)
6
6
  @root = node.root
7
+ @root.freeze
7
8
  end
8
9
 
9
10
  # Degree
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RootedTree
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rooted_tree
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
  - Sebastian Lindberg