Class: SoberSwag::Nodes::Binary
- Defined in:
- lib/sober_swag/nodes/binary.rb
Overview
A binary node: has a left and right hand side. Basically a node of a binary tree.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#lhs ⇒ SoberSwag::Nodes::Base
readonly
The left-hand node.
-
#rhs ⇒ SoberSwag::Nodes::Base
readonly
The right-hand node.
Instance Method Summary collapse
-
#cata(&block) ⇒ Object
Maps over the LHS side first, then the RHS side, then the root.
-
#deconstruct ⇒ Array(SoberSwag::Nodes::Base, SoberSwag::Nodes::Base)
Deconstructs into an array of
[lhs, rhs]
. -
#deconstruct_keys(_keys) ⇒ Object
Deconstruct into a hash of attributes.
-
#initialize(lhs, rhs) ⇒ Binary
constructor
A new instance of Binary.
-
#map(&block) ⇒ Object
Maps over the LHS side first, then the RHS side, then the root.
Methods inherited from Base
Constructor Details
#initialize(lhs, rhs) ⇒ Binary
Returns a new instance of Binary.
10 11 12 13 |
# File 'lib/sober_swag/nodes/binary.rb', line 10 def initialize(lhs, rhs) @lhs = lhs @rhs = rhs end |
Instance Attribute Details
#lhs ⇒ SoberSwag::Nodes::Base (readonly)
Returns the left-hand node.
17 18 19 |
# File 'lib/sober_swag/nodes/binary.rb', line 17 def lhs @lhs end |
#rhs ⇒ SoberSwag::Nodes::Base (readonly)
Returns the right-hand node.
21 22 23 |
# File 'lib/sober_swag/nodes/binary.rb', line 21 def rhs @rhs end |
Instance Method Details
#cata(&block) ⇒ Object
Maps over the LHS side first, then the RHS side, then the root.
41 42 43 44 45 46 47 48 |
# File 'lib/sober_swag/nodes/binary.rb', line 41 def cata(&block) block.call( self.class.new( lhs.cata(&block), rhs.cata(&block) ) ) end |
#deconstruct ⇒ Array(SoberSwag::Nodes::Base, SoberSwag::Nodes::Base)
Deconstructs into an array of [lhs, rhs]
27 28 29 |
# File 'lib/sober_swag/nodes/binary.rb', line 27 def deconstruct [lhs, rhs] end |
#deconstruct_keys(_keys) ⇒ Object
Deconstruct into a hash of attributes.
33 34 35 |
# File 'lib/sober_swag/nodes/binary.rb', line 33 def deconstruct_keys(_keys) { lhs: lhs, rhs: rhs } end |
#map(&block) ⇒ Object
Maps over the LHS side first, then the RHS side, then the root.
54 55 56 57 58 59 |
# File 'lib/sober_swag/nodes/binary.rb', line 54 def map(&block) self.class.new( lhs.map(&block), rhs.map(&block) ) end |