Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby: How to load a file into interactive ruby console (IRB)?

Tags:

ruby

irb

I am using IRB (interactive ruby console) to learn how to program with Ruby. How do I load a file into the console if I write my programs in a text editor first?

like image 279
nbonbon Avatar asked Oct 28 '12 19:10

nbonbon


People also ask

How do I use IRB in Ruby?

To use it, you launch the irb executable and type your Ruby code at the prompt. IRB evaluates the code you type and displays the results. IRB gives you access to all of Ruby's built-in features, as well as any libraries or gems you've installed.

How do I open IRB in terminal?

To access IRB, just type irb in the terminal. IRB allows you to do anything you can do in a Ruby file. For instance, you can do math, get the time by typing Time. now , or print text to the screen.

How do I start Ruby interactive console?

Open Interactive Ruby Open up IRB (which stands for Interactive Ruby). If you're using macOS open up Terminal and type irb, then hit enter. If you're using Linux, open up a shell and type irb and hit enter. If you're using Windows, open Interactive Ruby from the Ruby section of your Start Menu.

What is IRB command?

IRB stands for “interactive Ruby” and is a tool to interactively execute Ruby expressions read from the standard input. The irb command from your shell will start the interpreter.


1 Answers

If you only need to load one file into IRB you can invoke it with irb -r ./your_file.rb if it is in the same directory.

This automatically requires the file and allows you to work with it immediately.

like image 171
PhilG Avatar answered Sep 17 '22 00:09

PhilG