A few more things in the Rails console

Posted by Jason King 10 months ago

Almost immediately after posting my last post on the Rails console a few more things came to mind. It has taken me this long to blog again :)

Let’s pick up from where we left off in the previous post with…

…cont.

A couple of things in the Rails console

Posted by Jason King 11 months ago

So for anyone who doesn’t know, the script/console in Rails runs up an irb process behind the scenes. It also loads Rails into the context, and a few other bits - but mainly it’s an irb session.

I’ve just been getting a couple of “Oh wow, I didn’t know that.” responses when I mention these things in #rubyonrails, so I thought I’d just post this here.

Thing 1: the underscore method

The return from every command that you enter into irb is available in the underscore method _. So, if you’re like me, you often run a command and then think that you should have assigned it to some variable, or pretty-printed it or something.

…cont.

Comments: 5 (view/add your own) Tags: console, irb