title: Creating an object of a different class within a class method
body: <p>I am trying to call a method that will create an object of another class. When I do, I get feedback that the object has been created, but I can't seem to to do anything with that object (such as call a method from that objects class). Here is an example:</p>
  
  <pre><code>class A
      def initialize
  
      end
  
      def generate
          var = B.new
      end
  end
  
  class B
      def initialize
  
      end
  
      def declare
          puts "I exist!"
      end
  end
  
  test = A.new
  test.generate
  var.declare
  </code></pre>
  
  <p>This returns an "Undefined local variable or method 'var'" error. Am I going about this wrong? The best I can figure is that I am creating this object only within the instance, but even when I try doing stuff with it in the instance it comes back undefined. Is there another way to do this I am not thinking of, or am I doing this wrong? Thanks!</p>