title: unable to access a method variable which is out of same file
body: <p>I am unable to use a method when I move a piece of code to another file.</p>
  
  <p>Below mentioned code works cause all the code is in one file.</p>
  
  <pre><code>require 'rubygems'
  require 'watir'
  require 'win32ole'
  require 'erb' 
  require 'ostruct' 
  require 'C:/classes/html.class'
  require 'C:/classes/Xls'
  require 'C:/classes/screen_capture'
  require 'C:/classes/RequiredRubies'
  include Watir
  begin
  
        xlFile = XLS.new(Dir.pwd + '/testdata.xls') 
        myData = xlFile.getRowRecords('a2:z3','Pit') 
        xlFile.close
        myData.each do |record| 
  
        @ie = IE.new 
        @ie.maximize
        @ie.goto (record['Url'])
        @ie.focus
  
  end
  end
  </code></pre>
  
  <p>In above code 'URL' is present in an excel sheet names testdata.xls. The above code works just fine. Lets say this file name is file1.rb</p>
  
  <p>But I want to move the opening of browser into different file so that I don't use this code in all the test files and use it in only one file and call from it to all other test. Below is the change which I have done but this does not work.</p>
  
  <p>In File1.rb I have kept</p>
  
  <p>All Required Files+new file where I have mentioned the common code to open the browser</p>
  
  <pre><code>require 'C:/function.rb
  
  include Watir
  include Commonfunctions
  
  begin
  
        xlFile = XLS.new(Dir.pwd + '/testdata.xls') 
        myData = xlFile.getRowRecords('a2:z3','Pit') 
        xlFile.close
        myData.each do |record| 
  
     openie = openbrowser
  
  end
  
  end
  </code></pre>
  
  <p>And I have created a file for opening the browser which I want to use as common function. Lets say this file name in function.rb</p>
  
  <p>All Required files+below code</p>
  
  <pre><code>include Watir
  
  module Commonfunctions
  
  
  def openbrowser
        @ie = IE.new 
        @ie.maximize
        @ie.goto (record['Url'])
        @ie.focus
  end
  
  end
  </code></pre>
  
  <p>Now when I run my file1.rb I get the below error</p>
  
  <pre><code>C:/function.rb:17:in `openbrowser': undefined local variable or method `reco
  rd' for main:Object (NameError)
          from test.rb:23:in `block in &lt;main&gt;'
          from test.rb:21:in `each'
          from test.rb:21:in `&lt;main&gt;'
  </code></pre>
  
  <p>The 'record' object is coming from different file which is my data drive. In that file this is the code where method record is present</p>
  
  <pre><code>    numRecords = myRange.Rows.Count
      (0..numRecords-1).each do |i|
        record=[]
        areas.each do |area|
          record.concat(area[i])
        end
        #Clean up formatting
        record.collect! do |x|
          if x.is_a?(Float) and x % 1 == 0
             x.to_i.to_s
           else
            x.to_s.strip
          end
        end
        data &lt;&lt; record
      end
      return data
    end
  </code></pre>
  
  <p>Can any one please help me to resolve this issue. I want to move all the common functions to one file and use those functions in all test instead of writing the same functions in all tests.</p>