title: Call a method in a class in another class in Ruby
body: <p>I was wondering how I could call a method in an instance of a class in another class.</p>
  
  <p>This is what I came up with</p>
  
  <pre><code>class ClassA
    def method
      return "This is a method_from_class_A"
    end
  end
  
  class ClassB
    def initialize
      @method_from_class_A=instance.method
    end
    def method_calls_method
      @method_from_class_A
    end
  end
  
  
  instance=ClassA.new
  
  instance2=ClassB.new
  
  puts instance2.method_calls_method
  </code></pre>
  
  <p>But I get this error:</p>
  
  <blockquote>
    <p>Testing.rb:9:in <code>initialize': undefined local variable or method
    </code>instance' for # (NameError)     from
    Testing.rb:19:in <code>new'    from Testing.rb:19:in</code>'</p>
  </blockquote>
  
  <p>How could I fix it?</p>
  
  <p>Thank you for your response.</p>