Class: CaRuby::ControlledValue
- Inherits:
-
Object
- Object
- CaRuby::ControlledValue
- Defined in:
- lib/caruby/helpers/controlled_value.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #descendants ⇒ Object
-
#initialize(value = nil, parent = nil) ⇒ ControlledValue
constructor
Creates a new ControlledValue with the given String value and ControlledValue parent.
- #to_s ⇒ Object
Constructor Details
#initialize(value = nil, parent = nil) ⇒ ControlledValue
Creates a new ControlledValue with the given String value and ControlledValue parent. If parent is not nil, then the new CV is added to the parent’s children.
11 12 13 14 15 |
# File 'lib/caruby/helpers/controlled_value.rb', line 11 def initialize(value=nil, parent=nil) @value = value self.parent = parent @children = Set.new end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
7 8 9 |
# File 'lib/caruby/helpers/controlled_value.rb', line 7 def children @children end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/caruby/helpers/controlled_value.rb', line 5 def parent @parent end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/caruby/helpers/controlled_value.rb', line 5 def value @value end |
Instance Method Details
#descendants ⇒ Object
17 18 19 |
# File 'lib/caruby/helpers/controlled_value.rb', line 17 def descendants children + children.map { |child| child.descendants.to_a }.flatten end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/caruby/helpers/controlled_value.rb', line 21 def to_s value end |