Class: MerkleTree::Node
- Inherits:
-
Object
- Object
- MerkleTree::Node
- Defined in:
- lib/merkletree.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#do_dump(depth) ⇒ Object
dump (recursive_worker).
-
#dump ⇒ Object
for debugging / testing add pretty printing (dump tree).
-
#initialize(value, left, right) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(value, left, right) ⇒ Node
Returns a new instance of Node.
24 25 26 27 28 |
# File 'lib/merkletree.rb', line 24 def initialize( value, left, right ) @value = value @left = left @right = right end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
21 22 23 |
# File 'lib/merkletree.rb', line 21 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
22 23 24 |
# File 'lib/merkletree.rb', line 22 def right @right end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
20 21 22 |
# File 'lib/merkletree.rb', line 20 def value @value end |
Instance Method Details
#do_dump(depth) ⇒ Object
dump (recursive_worker)
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/merkletree.rb', line 35 def do_dump( depth ) ## dump (recursive_worker) depth.times { print ' ' } print "#{depth}:[#{value}] " if @left print '{' puts @left.do_dump( depth+1 ) @right.do_dump( depth+1) if @right # note: make right node optional (might be nil/empty) depth.times { print ' ' } print '}' end puts end |
#dump ⇒ Object
for debugging / testing add pretty printing (dump tree)
33 |
# File 'lib/merkletree.rb', line 33 def dump() do_dump( 0 ); end |