Method: NetworkX::Graph#add_node

Defined in:
lib/networkx/graph.rb

#add_node(node, **node_attrs) ⇒ Object

Adds a node and its attributes to the graph

Examples:

Add a node with attribute 'type'

graph.add_node("Noida", type: "city")

Parameters:

  • the node object

  • the hash of the attributes of the node



68
69
70
71
72
73
74
75
# File 'lib/networkx/graph.rb', line 68

def add_node(node, **node_attrs)
  if @nodes.has_key?(node)
    @nodes[node].merge!(node_attrs)
  else
    @adj[node] = {}
    @nodes[node] = node_attrs
  end
end