# Aliasing, require\_dependency and require

**URL:** <https://www.ruby-forum.com/t/aliasing-require-dependency-and-require/88710>\
**Category:** Rails\
**Created:** [March 13, 2007, 6:38pm UTC](https://www.ruby-forum.com/t/aliasing-require-dependency-and-require/88710 "2007-03-13T18:38:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![saimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@saimon](https://www.ruby-forum.com/u/saimon)\
**Post date:** [March 13, 2007, 6:38pm UTC](https://www.ruby-forum.com/t/aliasing-require-dependency-and-require/88710/1 "2007-03-13T18:38:23Z")

</div>

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.

[http://pastie.caboo.se/46630](http://pastie.caboo.se/46630)

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  
app/controllers/application.rb

- 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  
method:

#speaker plugin init.rb

#require ‘application’  
require\_dependency ‘application’

module Speaker  
def self.included(base)  
base.alias\_method\_chain :say\_hello, :speaker  
end

protected

```
def say_hello_with_speaker
  puts "Hello speaker...."
end

```

end

ApplicationController.send(:include, Speaker)

Any help heres is much appreciated…

Regards,

Saimon
