title: Calling a method of a foreign object from a parameter (Ruby)
body: <p>Everyone,</p>
  
  <p>I'm working on an assignment for a class I'm taking at university this year and we're supposed to make an implementation of a graph in Ruby.  This is my first experience with Ruby in this setting, so I'm having a hard time with the whole weakly typed aspect of it.</p>
  
  <p>I'm trying to have each vertex store the edges incident to it like</p>
  
  <pre><code>def new_edge v1, v2, *lv                                                      
      edge = MyEdge.new *lv
      v1.incident_edges.push(edge)
      v2.incident_edges.push(edge)
      return edge 
  end
  </code></pre>
  
  <p>So, this method takes two vertexes and an optional name as parameters.  I also have <code>attr_accessor :incident_edges</code> in the MyVertex class.</p>
  
  <p>The problem is that when I try to run it with rspec, I get `undefined method     incident_edges' for nil:NilClass, which makes sense since Ruby doesn't know what type the object is.  My question is if there is a way to get this to work or should I just use an adjacency matrix for this?</p>