Class: Graph::Attribute
- Inherits:
-
Struct
- Object
- Struct
- Graph::Attribute
- Defined in:
- lib/graph.rb
Overview
An attribute for a graph, node, or edge. Really just a composable string (via #+) with a convenience method #<< that allows you to “paint” nodes and edges with this attribute.
Instance Attribute Summary collapse
-
#attr ⇒ Object
(also: #to_s)
Returns the value of attribute attr.
Instance Method Summary collapse
-
#+(style) ⇒ Object
Compose a new attribute from two existing attributes:.
-
#<<(thing) ⇒ Object
“Paint” graphs, nodes, and edges with this attribute.
Instance Attribute Details
#attr ⇒ Object Also known as: to_s
Returns the value of attribute attr
347 348 349 |
# File 'lib/graph.rb', line 347 def attr @attr end |
Instance Method Details
#+(style) ⇒ Object
Compose a new attribute from two existing attributes:
bad_nodes = red + filled + diamond
374 375 376 |
# File 'lib/graph.rb', line 374 def + style Attribute.new "#{self}, #{style}" end |
#<<(thing) ⇒ Object
“Paint” graphs, nodes, and edges with this attribute.
red << node1 << node2 << node3
is the same as:
node1.attributes << red
node2.attributes << red
node3.attributes << red
359 360 361 362 |
# File 'lib/graph.rb', line 359 def << thing thing.attributes << self self end |