Class: Fr::TZipper::Node
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#cons(tail = []) ⇒ Object
This is implemented in object.rb.
- #copy(changes = {}) ⇒ Object
-
#initialize(value, children = []) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
-
#leaf? ⇒ Boolean
Allow any node to have children.
Constructor Details
#initialize(value, children = []) ⇒ Node
Returns a new instance of Node.
10 11 12 13 |
# File 'lib/fr/tzipper/node.rb', line 10 def initialize(value, children = []) @value, @children = value, children end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
8 9 10 |
# File 'lib/fr/tzipper/node.rb', line 8 def children @children end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/fr/tzipper/node.rb', line 6 def value @value end |
Class Method Details
.build(value, children) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fr/tzipper/node.rb', line 43 def build(value, children) Node.new(value, children.map do |c| if Array === c value_, *children_ = c Node.build(value_, children_) else Node.new(c) end end) end |
Instance Method Details
#cons(tail = []) ⇒ Object
This is implemented in object.rb
27 28 29 |
# File 'lib/fr/tzipper/node.rb', line 27 def cons(tail = []) [self] + tail end |
#copy(changes = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/fr/tzipper/node.rb', line 15 def copy(changes = {}) Node.new \ changes.fetch(:value, @value), changes.fetch(:children, @value) end |
#inspect ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/fr/tzipper/node.rb', line 31 def inspect if @children.empty? "Leaf(#{@value.inspect})" else "Node(#{@value.inspect}, #{@children.map(&:inspect).join(", ")})" end end |
#leaf? ⇒ Boolean
Allow any node to have children
22 23 24 |
# File 'lib/fr/tzipper/node.rb', line 22 def leaf? false end |