title: Why do I get an undefined method `xpath' for #?
body: <p>I have the following XML structure:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;agencies&gt;
    &lt;city&gt;
      &lt;name&gt;New York&lt;/name&gt;
      &lt;address&gt;Street A, 101&lt;/address&gt;
      &lt;phone&gt;111-222-333&lt;/phone&gt;
    &lt;/city&gt;
    &lt;city&gt;
      &lt;name&gt;Chicago&lt;/name&gt;
      &lt;address&gt;Street B, 201&lt;/address&gt;
      &lt;phone&gt;111-222-333&lt;/phone&gt;
    &lt;/city&gt;
  &lt;/agencies&gt;
  </code></pre>
  
  <p>and I'm trying to create a Ruby class to work with it.</p>
  
  <p>I created the class file:</p>
  
  <pre><code>require 'nokogiri'
  
  class Agency
  
    def initialize(arg)
      @file = arg.gsub(/-/,'_')
      @doc = Nokogiri::XML(open("db/agencies/#{@file}.xml"))
    end
  
    def find_offices
      @doc.xpath('//agencies/city').map do |i|
        { 'name' =&gt; xpath('name') }
      end
      #@entries = @doc.xpath('//agencies/city').map do |i|
      #  { 'name' =&gt; xpath('name').inner_text, 'address' =&gt; xpath('address').inner_text, 'phone' =&gt; xpath('phone').inner_text }
      #end
    end
  end
  </code></pre>
  
  <p>For my controller I have:</p>
  
  <pre><code>class AgenciesController &lt; ApplicationController
  
    def index
      @prefectures = Prefecture.all
    end
  
    def list
      @prefecture = Agency.new(params[:prefecture_name])
      @offices = @prefecture.find_offices
    end
  end
  </code></pre>
  
  <p>The <code>list</code> method returns the following error:</p>
  
  <pre><code>NoMethodError in AgenciesController#list
  
  undefined method `xpath' for #&lt;Agency:0x9e7f280&gt;
  Rails.root: /home/kleber/projects/rails_apps/job_board2
  
  Application Trace | Framework Trace | Full Trace
  app/models/agency.rb:13:in `block in find_offices'
  app/models/agency.rb:12:in `map'
  app/models/agency.rb:12:in `find_offices'
  app/controllers/agencies_controller.rb:9:in `list'
  </code></pre>