Method: NetworkX::Graph#add_nodes

Defined in:
lib/networkx/graph.rb

#add_nodes(nodes) ⇒ Object

Adds multiple nodes to the graph

Examples:

Adds multiple nodes with attribute 'type'

graph.add_nodes([["Noida", type: "city"], ["Kgp", type: "town"]])

Parameters:

  • nodes (Array<Object, Hash{ Object => Object }>)

    the Array of pair containing nodes and its attributes



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/networkx/graph.rb', line 83

def add_nodes(nodes)
  case nodes
  when Set, Array
    nodes.each { |node, node_attrs| add_node(node, **(node_attrs || {})) }
  when Range
    nodes.each { |node| add_node(node) }
  else
    raise ArgumentError, 'Expected argument to be an Array/Set/Range of nodes, ' \
                         "received #{nodes.class.name} instead."
  end
end