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
20
votes
6 answers

If I defined a Ruby method in IRB, how do I edit that method without retyping everything?

Say I am running IRB and I type this into the console: def full_name(first, last) puts "Your full name is: #{first, ' ', last}" end Say, that I wanted to edit that to include the parameter middle, how would I just bring back up that same method…
marcamillion
  • 32,933
  • 55
  • 189
  • 380
20
votes
4 answers

In IRB, can I view the source of a method I defined earlier?

If I define a method in IRB, is there any way to review its source later in the session? > def my_method > puts "hi" > end Several screens of output later I'd like to be able to write something like > source my_method and get back: => def…
djb
  • 5,591
  • 5
  • 41
  • 47
20
votes
3 answers

Reload rubygem in IRB

Is there a way to "reload" or "refresh" a rubygem in memory? As i'm playing in irb, occasionally I like to modify my gem files, and if i require the same gem, it does not update into memory and gives the output "false". Currently I have to exit IRB,…
Schneems
  • 14,918
  • 9
  • 57
  • 84
19
votes
2 answers

Load file to rails console with access to variables defined in this file

I work with rails console and often i need to preload some ruby code to work with. #file that i want to load in rails console #my_file.rb a = 1 b = 2 puts a + b When i run my console with ./script/console rails-console :001 > load 'my_file.rb' 3 …
Vladimir Tsukanov
  • 4,269
  • 8
  • 28
  • 34
19
votes
4 answers

How can I access a variable defined in a Ruby file I required in IRB?

The file welcome.rb contains: welcome_message = "hi there" But in IRB, I can't access the variable I just created: require './welcome.rb' puts welcome_message # => undefined local variable or method `welcome_message' for main:Object What is the…
BuddyJoe
  • 69,735
  • 114
  • 291
  • 466
18
votes
2 answers

rbenv irb history is not saving

I install ruby via rbenv-installer. When I use irb console, I can use history by pressing up and down on keyboard. And when I exited from console and start it again, I can't use prewious history. When I press up-arrow-button, nothing was…
arturtr
  • 1,115
  • 9
  • 18
17
votes
5 answers

How can I obtain an interactive shell (like Ruby's irb) for Java?

I spent the last year doing Ruby development, and during that time I discovered irb, which makes running little "code experiments" easy and fun. I've recently switched teams and am now doing Java development, and I've found that I really miss my…
Dan Barowy
  • 2,270
  • 24
  • 35
17
votes
7 answers

How to format irb command prompt

Previously I was using Ruby 1.8 and my irb command prompt used to look like this: Air ~: irb >> a = 1 => 1 >> b = 2 => 2 >> a + b => 3 I installed rvm (and Ruby 1.9.2) and now my irb command prompt looks like this: Air ~: irb ruby-1.9.2-p180 :001 >…
vince
  • 2,374
  • 4
  • 23
  • 39
16
votes
4 answers

Pasting text into IRB is incredibly slow. Readline issue?

When I paste the following text into IRB or PRY running under ruby-enterprise-2011.03, it takes 13 seconds. # Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pasting isn't…
John Douthat
  • 40,711
  • 10
  • 69
  • 66
16
votes
6 answers

How do I make vi editing-mode work in IRB when using RVM?

I "set editing-mode vi" in my .inputrc on my Mac OS system, which allows vi editing in IRB. When I'm using a RVM Ruby, the IRB sessions don't process this directive. Does anyone know a solution?
pixelearth
  • 13,674
  • 10
  • 62
  • 110
16
votes
3 answers

automatically load project's environment to irb

Rails has useful command rails console, which downloads all necessary data and then we can interact with rails project in irb. Is there the same technique for Ruby project (built on Ruby language)? By this trick I can play with Ruby project in the…
megas
  • 21,401
  • 12
  • 79
  • 130
16
votes
1 answer

Rails3 irb console vs rails console?

Using Rails3 and Ruby 1.9.2, I am new, just learning Ruby/Rails-- When I run irb I end up with irb(main):001:0> which is fine. However when I run rails console I also end up with irb(main):001:0> and I thought, based on the book I'm reading and…
tehaaron
  • 2,250
  • 10
  • 31
  • 54
16
votes
3 answers

rails console fails with `Switch to inspect mode` in windows

I create a rails project by rails new foo, then cd foo, and run rails c. Then I got message like this. DL is deprecated, please use Fiddle Loading development environment (Rails 4.0.2) Switch to inspect mode. That's all. I can't use rails…
ironsand
  • 14,329
  • 17
  • 83
  • 176
16
votes
7 answers

irb history not working

in ~/.irbrc i have these lines: require 'irb/ext/save-history' #History configuration IRB.conf[:SAVE_HISTORY] = 100 IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history" and yet when i run irb and hit the up arrow nothing happens. also the…
quinn
  • 5,508
  • 10
  • 34
  • 54
14
votes
3 answers

Why does hitting the left arrow in irb give me "^[[D"?

I'm using Ubuntu Server 10 lucid, ruby 1.9.2-p0. In irb, the left arrow shows ^[[D. Any idea?
mko
  • 21,334
  • 49
  • 130
  • 191
1 2
3
51 52