The Rails 3.2.7 console exits if I type ‘n’ in it and return. This isn’t a feature of IRB; n is treated as an undeclared variable there. Googling ‘n’ with rails console (unsurprisingly) turned up nothing.
Can someone explain why Rails introduces this alias?
The method is added to the main object by the
debuggergem. As @weexpectedTHIS pointed out, this doesn’t happen in a vanilla Rails app. Uncommentgem 'debugger'andbundle install, andnacts as quit.Just for fun, I thought I’d toss in some of my detective work. The methods callable in irb appear to be methods on the
mainobject. It doesn’t seem like you can reference main by name:but you can still get the main object:
I have tab completion enabled for objects in my IRB console, but for some reason, it fetches extra results when I don’t use it on a named variable available to the current scope:
<200 methods is skimmable, so browsing through there, I could see that
nwas indeed a method on the main object. Just to verify, typing:kills the console. That means I can now find out where it’s defined:
I got stuck here, since that file dynamically assigns many methods, but none that I could discern with the command ‘n’.
A coworker suggested I try this in a fresh Rails app, and that led me to experimenting with different gems. After a quick glance through the list,
debuggerseemed like a more likely choice.To anyone who’s read this far, I’ll happily re-accept another answer that can explain where and why the
debuggergem introducesn.