rooted_tree 0.2.2 → 0.2.3

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: 22a5b2a13278deccce0118fecd19ba5d65e39a4c
4
- data.tar.gz: f2de5a5dba41d23f396e325889f9ed2dd6d468af
3
+ metadata.gz: 70e0e394dca29c945f79679ac2ade085f9210412
4
+ data.tar.gz: d8e06827ee6b284d2cc39140229125b5f0232428
5
5
  SHA512:
6
- metadata.gz: 492a612d75f800c8e3ab638beb1c7bc9f352125eb29ceff47bf2a38855b12bbbb4675846dd52a4813877baf5402da1f39a6b53880c2c9adf9083621c50122dc7
7
- data.tar.gz: cd0a3ef730dca13e6d083bdf44ed0b834a973121dff0ca05369fd355f8c6b30a9be1fd957dc5b9e60dd5b0ba1395964fe63122e0914a4593441b791c6b4b87f3
6
+ metadata.gz: 2b63502165e12f8d0ff158f07c2d2c010485f85f227ffbe05b1f73cc541907601c8a642816e568b8575a6cb7f7b2f4b41d901e5ffafe926a34b855077ea1764b
7
+ data.tar.gz: 29c29640e1f5e18812f994a76646e91e15b7e0bc5df125056707901e197a97455d5442cb6e19ff758221fc361663646d50a69b9d64331db5a836e51136c96346
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/richtext.png)](http://badge.fury.io/rb/rooted_tree)
4
4
  [![Build Status](https://travis-ci.org/seblindberg/ruby-rooted_tree.svg?branch=master)](https://travis-ci.org/seblindberg/ruby-rooted_tree)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/seblindberg/ruby-rooted_tree/badge.svg?branch=master)](https://coveralls.io/github/seblindberg/ruby-rooted_tree?branch=master)
6
+ [![Inline docs](http://inch-ci.org/github/seblindberg/ruby-rooted_tree.svg?branch=master)](http://inch-ci.org/github/seblindberg/ruby-rooted_tree)
6
7
 
7
8
  A tree is a connected graph with no cycles. There, that is plenty of explanation. Please refer to https://en.wikipedia.org/wiki/Tree_structure for a more in depth description, but if you need one this library probably is not for you.
8
9
 
@@ -33,10 +33,10 @@ module RootedTree
33
33
 
34
34
  def self.[](value = nil)
35
35
  return value if value.is_a? self
36
- self.new value
36
+ new value
37
37
  end
38
38
 
39
- def initialize value = nil
39
+ def initialize(value = nil)
40
40
  @parent = nil
41
41
  @next = nil
42
42
  @prev = nil
@@ -56,9 +56,9 @@ module RootedTree
56
56
  end
57
57
 
58
58
  def freeze
59
- super
60
59
  @value.freeze
61
60
  children.each(&:freeze)
61
+ super
62
62
  end
63
63
 
64
64
  # Leaf?
@@ -399,15 +399,19 @@ module RootedTree
399
399
  # Add
400
400
  #
401
401
  # Add two roots together to create a larger tree. A new common root will be
402
- # created and returned.
402
+ # created and returned. Note that if the any of the root nodes are not
403
+ # frozen they will be modified, and as a result seize to be roots.
403
404
 
404
405
  def +(other)
405
406
  unless root? && other.root?
406
407
  raise StructureException, 'Only roots can be added'
407
408
  end
408
409
 
409
- root = self.class.new
410
- root << self << other
410
+ a = frozen? ? dup : self
411
+ b = other.frozen? ? other.dup : other
412
+
413
+ ab = self.class.new
414
+ ab << a << b
411
415
  end
412
416
 
413
417
  # Equality
@@ -465,7 +469,7 @@ module RootedTree
465
469
  # |--Node:0x3ffd64c1fd30
466
470
  # | |--Node:0x3ffd64c1f86c
467
471
  # | +--Node:0x3ffd64c1f63c
468
- # +--Entety:0x3ffd64c1f40c
472
+ # +--Node:0x3ffd64c1f40c
469
473
  #
470
474
  # By passing `as_array: true` the method will instead return an array
471
475
  # containing each of the output lines. The method also accepts a block
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RootedTree
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rooted_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Lindberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-25 00:00:00.000000000 Z
11
+ date: 2016-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler