rails/rails — pull request #3509 by amatsuda (2011-11-04 06:33:30+00:00)
Title: move Rails console top level methods to IRB context

Currently, methods available in Rails console (such as `app`, `helper`, `reload`, etc.) are defined on Ruby's top level.
That means, these methods are injected into all Objects. In fact, we can do something funny like this on our Rails console.

```
> puts 'foobar'.send(:app)
#
```

```
> puts nil.send(:controller)
#
```

Reading IRB code, I found the IRB way is, to define this sort of methods in a module named IRB::ExtendCommandBundle, then IRB automatically includes (extends) these methods in IRB console's context.
For example, you see, you can call `irb_jobs` method in your IRB but the following code raises `NoMethodError: undefined method `irb_jobs'`, because this method is mixed into IRB's "main" context via IRB::ExtendCommandBundle.

```
Object.new.send(:irb_jobs)
```

Attached a patch and tests for Rails console to follow this IRB way. I confirmed it runs on MRI 1.8, 1.9, JRuby and Rubinius.