title: Overriding path helpers in Rails using define_method
body: <p>I need to override quite a few path helper methods in Ruby on Rails and call super from them. My standard approach would be:<br>
  <strong>path_helper.rb</strong></p>
  
  <pre><code>def business_path(business)
    if params[:city_id] == 2
      moscow_business_path(business)
    else
      super
    end
  end
  </code></pre>
  
  <p>But I have a lot of these methods, so I want to define them dynamically like this:</p>
  
  <pre><code>  %i[root businesses business ...].each do |path_method|
      method_name = "#{path_method}_path"
      old_method = method(method_name)
      define_method(method_name) do |*args|
        if params[:city_id] == 2
          public_send("moscow_#{method_name}")
        else
          old_method.call(*args)
        end
      end
    end
  </code></pre>
  
  <p>But I get this error:</p>
  
  <pre><code> /home/leemour/Ruby/burobiz/app/helpers/path_helper.rb:31:in `method': undefined method `root_path' for class `Module' (NameError) 
   from /home/leemour/Ruby/burobiz/app/helpers/path_helper.rb:31:in `block in &lt;module:PathHelper&gt;'
   from /home/leemour/Ruby/burobiz/app/helpers/path_helper.rb:29:in `each' 
   from /home/leemour/Ruby/burobiz/app/helpers/path_helper.rb:29:in `&lt;module:PathHelper&gt;' 
   from /home/leemour/Ruby/burobiz/app/helpers/path_helper.rb:1:in `&lt;top (required)&gt;' 
   from /home/leemour/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:476:in `load'
  </code></pre>
  
  <p>I guess helper modules haven't been included yet, so there is no original path helper method to capture with <code>method(method_name)</code>. Then I guess I'd have to use <code>self.included</code> hook but I couldn't figure it. How can I adjust this code to make it work? (I don't want to use eval).</p>