How to Save an IRB Session
The Interactive Ruby Shell (IRB) is a command-line program that allows developers to type a Ruby program with immediate interpretation and execution of their commands. This allows the developer to experiment with the output of different functions in real time, step through output line by line to assist with debugging, and create session files that allow the application written in IRB to be invoked or edited later by the user or system script. You can edit your IRB initialization script to have it automatically record each session to a file.
Instructions
-
-
1
Open the "Start" menu and type "%AppData%" in the search bar. Press "Enter."
-
2
Double-click "Ruby" and then double-click ".irbrc."
-
-
3
Open the file in Notepad by selecting it from the default applications list that appears on the screen.
-
4
Add the following lines of code to the end of the file:
module IRB
def IRB.buffer; @log; end
@log = ""
class WorkSpace
alias backup_evaluate evaluate
def evaluate(context, statements, file = __FILE__, line = __LINE__)
result = backup_evaluate(context, statements, file, line)
if /IRB\.buffer/.match(statements)
IRB.buffer << "#{statements.chomp}\n"
else
IRB.buffer << "#{statements.chomp} #=> #{result.inspect}\n"
end
result
end
end
end
-
5
Save the file by clicking "File," then "Save." When you begin a new IRB session, the file will be automatically saved in a file called "IRB.buffer" in the directory you launched your Ruby application from.
-
1