Questions tagged [irb]

Interactive Ruby (IRB) is a shell for programming in Ruby. The program can be launched from a command prompt and allows the execution of Ruby commands line by line.

Interactive Ruby Shell (IRB) is a shell for programming in Ruby. The program can be launched from a command prompt and allows the execution of Ruby commands line by line. It features command history, line editing capabilities, and job control, and is able to communicate directly as a shell script over the Internet and interact with a live server. It was developed by Keiju Ishitsuka.

772 questions
318
votes
6 answers

How to get the current working directory's absolute path in Ruby?

I'm running Ruby on Windows though I don't know if that should make a difference. All I want to do is get the current working directory's absolute path. Is this possible from irb? Apparently from a script it's possible using…
Dexygen
  • 12,287
  • 13
  • 80
  • 147
203
votes
21 answers

How Do You Clear The IRB Console?

How do you clear the IRB console screen?
John Topley
  • 113,588
  • 46
  • 195
  • 237
139
votes
12 answers

How to get nice formatting in the Rails console

I want to get something like this to look nice: >> ProductColor.all => [#, #
Tom Lehman
  • 85,973
  • 71
  • 200
  • 272
108
votes
8 answers

Ruby: How to load a file into interactive ruby console (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?
nbonbon
  • 1,660
  • 3
  • 18
  • 27
102
votes
7 answers

How to suppress Rails console/irb outputs

I was testing some DB entries in our production server in Rails Console where almost all the commands were producing a huge number of lines of output and causing the ssh channel to hang. Is there a way to suppress the console/irb screenfuls?
ghtn
  • 2,233
  • 3
  • 15
  • 7
98
votes
3 answers

How to run a .rb file from IRB?

I am starting out with Ruby on Rails. I am currently going through a tutorial that says that I have to run a .rb file from IRB to create a .xml file in my current directory. My question is how do I run a .rb file in IRB? I tried the following: just…
Katrina
  • 981
  • 1
  • 7
  • 5
97
votes
4 answers

Stop rails console from printing out the object at the end of a loop

If I, say, loop through all the instances of a given model and output something from each, at the end, irb will still print the entire object. If the object ends up taking hundreds of lines, it'll be a long way up before I see what I was actually…
dsp_099
  • 5,801
  • 17
  • 72
  • 128
72
votes
3 answers

Disable irb autocomplete

The latest version of irb introduced an autocomplete that is quite buggy and I don't generally like to be distracted by an autocomplete, any idea how I can disable it? Related question: How to disable Pry autocomplete?
Dorian
  • 7,749
  • 4
  • 38
  • 57
72
votes
5 answers

Ruby: How to make IRB print structure for Arrays and Hashes

When I make a new array/hash in irb, it prints out a nice format to show the structure, ex. ["value1", "value2", "value3"] {"key1" => "value1"} ... but when I try to print out my variables using puts, I get them…
neezer
  • 19,720
  • 33
  • 121
  • 220
71
votes
4 answers

How can I reload a script in IRB?

I am writing a Ruby script for use in the Rails environment, but I chose to run it from irb because reloading the Rails console can be a pain. Now the wait time is much shorter from irb, but I'm bothered that I have to restart irb and require the…
picardo
  • 24,530
  • 33
  • 104
  • 151
62
votes
3 answers

How to enable auto completion in Ruby's IRB

When I use Merb's built in console, I get tab auto-completion similar to a standard bash prompt. I find this useful and would like to enable it in non-merb IRB sessions. How do I get auto-completion in IRB?
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
50
votes
6 answers

Load and use fixture in rails console

I wonder if there's a way to load and/or use fixture in rails console. Actually, I'd like to create a user from my fixture users.yml to do some testing without having to go through all the "pain" of doing User.new(:name = "John", :email = "..") each…
Patrick Pruneau
  • 669
  • 3
  • 7
  • 14
43
votes
6 answers

How do I drop to the IRB prompt from a running script?

Can I drop to an IRB prompt from a running Ruby script? I want to run a script, but then have it give me an IRB prompt at a point in the program with the current state of the program, but not just by running rdebug and having a breakpoint.
Daniel Huckstep
  • 5,368
  • 10
  • 40
  • 56
39
votes
7 answers

How do you list the currently available objects in the current scope in ruby?

I'm new to ruby and I'm playing around with the IRB. I found that I can list methods of an object using the ".methods" method, and that self.methods sort of give me what I want (similar to Python's dir(builtins)?), but how can I find the methods of…
monkut
  • 42,176
  • 24
  • 124
  • 155
38
votes
4 answers

How to suppress the output of return value in IRB/Rails Console?

An example is if I go into IRB and do the following: jruby-1.6.7 :026 > puts [1,2,3,4,5] 1 2 3 4 5 => nil Is there anyway to suppress the nil? The problem is if I put in a large data structure, it spams something an other irrelevant return…
randombits
  • 47,058
  • 76
  • 251
  • 433
1
2 3
51 52