Class: Hydrangea::Node
- Inherits:
-
Object
- Object
- Hydrangea::Node
- Defined in:
- lib/hydrangea/node.rb
Instance Attribute Summary collapse
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#previous ⇒ Object
readonly
Returns the value of attribute previous.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #history(&transform) ⇒ Object
-
#initialize(state:, value:, previous: nil) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(state:, value:, previous: nil) ⇒ Node
Returns a new instance of Node.
5 6 7 8 |
# File 'lib/hydrangea/node.rb', line 5 def initialize(state:, value:, previous: nil) @state, @value, @previous = state, value, previous @first = previous && previous.first || self end |
Instance Attribute Details
#first ⇒ Object (readonly)
Returns the value of attribute first.
3 4 5 |
# File 'lib/hydrangea/node.rb', line 3 def first @first end |
#previous ⇒ Object (readonly)
Returns the value of attribute previous.
3 4 5 |
# File 'lib/hydrangea/node.rb', line 3 def previous @previous end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
3 4 5 |
# File 'lib/hydrangea/node.rb', line 3 def state @state end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/hydrangea/node.rb', line 3 def value @value end |
Instance Method Details
#history(&transform) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hydrangea/node.rb', line 10 def history(&transform) node, history = self, [] transform ||= :itself.to_proc loop do history << transform[node] break if node.previous.nil? node = node.previous end history end |
#inspect ⇒ Object
29 30 31 |
# File 'lib/hydrangea/node.rb', line 29 def inspect "#<#{self.class.name}#{to_s}>" end |
#to_a ⇒ Object
21 22 23 |
# File 'lib/hydrangea/node.rb', line 21 def to_a [state,value] end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/hydrangea/node.rb', line 25 def to_s "(#{to_a.map(&:inspect).join(',')})" end |