Class: Node
- Inherits:
-
Object
- Object
- Node
- Defined in:
- lib/rgraph/node.rb
Instance Attribute Summary collapse
-
#neighbours ⇒ Object
Returns the value of attribute neighbours.
Instance Method Summary collapse
- #[](attribute) ⇒ Object
- #degree ⇒ Object
- #has_neighbour?(node) ⇒ Boolean
-
#initialize(attributes) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(attributes) ⇒ Node
Returns a new instance of Node.
4 5 6 7 |
# File 'lib/rgraph/node.rb', line 4 def initialize(attributes) @attributes = attributes @neighbours = [] end |
Instance Attribute Details
#neighbours ⇒ Object
Returns the value of attribute neighbours.
2 3 4 |
# File 'lib/rgraph/node.rb', line 2 def neighbours @neighbours end |
Instance Method Details
#[](attribute) ⇒ Object
17 18 19 |
# File 'lib/rgraph/node.rb', line 17 def [](attribute) @attributes[attribute] end |
#degree ⇒ Object
9 10 11 |
# File 'lib/rgraph/node.rb', line 9 def degree @neighbours.size end |
#has_neighbour?(node) ⇒ Boolean
13 14 15 |
# File 'lib/rgraph/node.rb', line 13 def has_neighbour?(node) @neighbours.include?(node) end |