This one is for the Ruby users. irb is the REPL that comes with Ruby, there is another one called Pry which is very popular. In fact when you SSH into Orderweb this is the REPL you get put into. It has some fun tricks that make poking around in code much easier. In my code examples >> is the pry prompt.
This one is better explained with a video but the basics of it is if you have the EDITOR environment variable set export EDITOR=vim or set it in your .pryrc Pry.config.editor = 'vim' you can then edit code. the edit command will open your text editor at a blank file saved in /tmp and you can write some ruby, save it and exit and it will bring you back to pry where your code will have been loaded in. If you edit again it will open the tmp file back up. The cool thing is you can edit specific methods with edit <method>. This one won't work on production containers but it's handy for local development.
>> edit
*inside vim*
def hi
puts "hi"
end
*save and exit*
=> :hi
>> hi
"hi"
>> edit
*file opens up again*
def hi
puts "hi there"
end
*save and exit*
=> :hi
>> hi
"hi there"
Rails is notorious for having magic methods that you have no idea where they come from, but Pry will tell you where the code is. Use the command show-source (alias $) with the name of the method you are after. This command has a whole bunch of options you can pass to it, such as -l to include line numbers and -a to show you all the source for all definitions it finds.
>> $ hi
From: pry-redefined(0x2b097969ab9c#hi) @ line 1:
Owner: Object
Visibility: public
Number of lines: 3
def hi
"hi"
end
>> $ -l puts
From: io.c (C Method):
Owner: Kernel
Visibility: private
Number of lines: 8
1: static VALUE
2: rb_f_puts(int argc, VALUE *argv, VALUE recv)
3: {
4: if (recv == rb_stdout) {
5: return rb_io_puts(argc, argv, recv);
6: }
7: return rb_funcallv(rb_stdout, rb_intern("puts"), argc, argv);
8: }
This is a small one but it's really handy. Have you ever been coding in pry and got a few levels of indentation deep only to mess up then get stuck trying to get out of it back to the top level? Well you should really give the edit command a go but if you are in this predicament type ! to clear the input buffer
>> def hi
| if true
| if false
| thing
| oh
| end
| oops I've messed up
| damn
| !
Input buffer cleared!
>>
There's a TON of other features in that gem, check out the wiki.
[1] https://github.com/pry/pry/wiki/Editor-integration [2] https://github.com/pry/pry/wiki/Source-browsing [3] https://github.com/pry/pry/wiki/User-Input#clear-the-input-buffer