Aliasing, require_dependency and require

I’d really appreciate it if someone [with a decent understanding of the
rails Dependencies mechanism] could help me explain the behaviour seen
in this pastie.

The desired behaviour is simply aliasing a method in
ApplicationController from a plugin while retaining automatic reloading
in dev mode.

The pastie is basically divided into 4 parts:

  • Setup of rails app and initial version of

  • Setup of plugin which will alias the method in application.rb and
    initial attempt without loading ‘application’

The interesting parts (for me) are the last two frames:

Firstly, I use require_dependency to load ApplicationController but as
you can see the aliasing doesn’t work (funnily enough the xxx_with/out
methods are defined).

Secondly, I use ‘require’ to load ApplicationController and here
aliasing works as it should but I’m losing reloading of application.rb.

The same behaviour is observed if I use the following module included

#speaker plugin init.rb

#require ‘application’
require_dependency ‘application’

module Speaker
def self.included(base)
base.alias_method_chain :say_hello, :speaker


def say_hello_with_speaker
  puts "Hello speaker...."


ApplicationController.send(:include, Speaker)

Any help heres is much appreciated…