-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
move Rails console top level methods to IRB context #3509
move Rails console top level methods to IRB context #3509
Conversation
Thanks and I agree that adding such methods to all objects is not a good idea, but would those changes also work with |
I don't know. I don't use Pry for Rails projects. If Pry wants to support Rails, maybe they aught to do something better than this (this insane script is linked from the readme. I don't think they're serious so far). Anyway, if you think Rails should be flexible enough so that users can choose their own console backend, probably I should better not directly monkey patch |
This is how I use pry for the rails console. I'll test if this works on pry as soon as I'm done running the rails tests. |
Nope, this doesn't work with (my setup of) pry. Would a better way be to put it in a Rails-specific module and include it into IRB however IRB does it when you run rails console and leave it to the user for pry? So for Pry I would do |
👍 @dvyjones. If Pry could have a module it could include from, it could also be easy to write a Pry plugin that made those methods available as Pry commands. |
…s Pry can include these methods
@dvyjones @robgleeson Thank you very much for your feedbacks :) Externalized the console helper methods into a module named |
Sounds good. Thank everyone for your work, merging. |
move Rails console top level methods to IRB context
There is a broken test with this, can you take a look to it?:
|
Ugh. Sorry for that. Made another push on this branch, but it seems a new commit doesn't appear on an already merged pull request, so I made another pr #3589. |
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.
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 raisesNoMethodError: undefined method
irb_jobs'`, because this method is mixed into IRB's "main" context via IRB::ExtendCommandBundle.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.