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
11
votes
1 answer

How to use RSpec expectations in irb

I'd want to use [1,2,3].should include(1) in irb. I tried: ~$ irb 1.9.3p362 :001 > require 'rspec/expectations' => true 1.9.3p362 :002 > include RSpec::Matchers => Object 1.9.3p362 :003 > [1,2,3].should include(1) TypeError: wrong argument type…
Andrei Botalov
  • 20,686
  • 11
  • 89
  • 123
10
votes
4 answers

Does the || operator evaluate the second argument even if the first argument is true?

I'm trying to evaluate the expression (a=10) || (rr=20) while the rr variable is not defined so typing rr in the ruby console before evaluating the previous expression returns rr NameError: undefined local variable or method `rr' for…
zeacuss
  • 2,563
  • 2
  • 28
  • 32
10
votes
5 answers

~/.irbrc not executed when starting irb or script/console

Here's what I've tried: 1. gem install awesome_print 2. echo "require 'ap'" >> ~/.irbrc 3. chmod u+x ~/.irbrc 4. script/console 5. ap { :test => 'value' } Result: NameError: undefined local variable or method `ap' for #
Patrick Klingemann
  • 8,884
  • 4
  • 44
  • 51
10
votes
3 answers

How do I dynamically create a local variable in Ruby?

I am trying to dynamically create local variables in Ruby using eval and mutate the local-variables array. I am doing this in IRB. eval "t = 2" local_variables # => [:_] eval "t" # => NameError: undefined local variable or method `t' for…
ppone
  • 581
  • 8
  • 21
10
votes
5 answers

Ruby. How can I copy and paste in irb on Windows?

How can I copy and paste in irb (Interactive Ruby Shell) on Windows?
sker
  • 17,842
  • 8
  • 37
  • 41
10
votes
3 answers

Can you 'require' ruby file in irb session, automatically, on every command?

I am currently editing a file, and I'm using irb to test the api: > require './file.rb' > o = Object.new > o.method I then want to be able to edit the file.rb, and be able to see changes immediately. Example: assume new_method did not exist when I…
Damien Roche
  • 13,189
  • 18
  • 68
  • 96
9
votes
3 answers

Reload rubygems in irb?

I've this script right now. def r(this) require this puts "#{this} is now loaded." rescue LoadError puts "The gem '#{this}' is missing." puts "Should I install it? [y/n]" data = gets if data =~ /yes|y/i puts "Installing #{this}, hold…
Linus Oleander
  • 17,746
  • 15
  • 69
  • 102
9
votes
3 answers

Ruby 1.9.2: irb throws ArgumentError: invalid byte sequence in UTF-8 when entering German Umlaut

I want to enter German Umlauts in my irb but get a weird error. I can enter any character of äöü without problems, but each of ÄÖÜß leads to the following error: $ irb ruby-1.9.2-p136 :001 > ? # here I entered Ü but it displays only…
Lorenz
  • 483
  • 5
  • 11
9
votes
1 answer

IRB analogue of python -i

I want to use IRB to run a script then give me an interactive prompt. I do this with python -i xy.py in Python, however irb xy.rb exits after execution. > python --help -i When a script is passed as first argument or the -c option is used,…
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
9
votes
2 answers

How do I compile Readline support into Ruby

My version of ruby was compiled with editline (on os x) and I miss the features of readline in irb. How do I recompile ruby with readline support?
samg
  • 3,496
  • 1
  • 25
  • 26
9
votes
2 answers

IRB doesn't respect dot (.) as a word-break character

I'm using irb on OS X, and when I press option left/right (or META+B/F) the cursor moves to the next/previous word. But irb doesn't wont to treat dot (.) character as a word separator. I've tried to add the (.) to the .irbrc, so it looks like this…
Dmitry Sokurenko
  • 6,042
  • 4
  • 32
  • 53
8
votes
1 answer

All commands in irb giving "NoMethodError: undefined method `write' for nil:NilClass"

I am trying to get the current ruby version from IRB but its giving me this error: >> RUBY_VERSION NoMethodError: undefined method `write' for nil:NilClass from /usr/local/lib/ruby/1.9.1/irb.rb:311:in `printf' from…
0xSina
  • 20,973
  • 34
  • 136
  • 253
8
votes
2 answers

Why does my IRB prompt with ANSI color codes mess up page up/down behavior with copy/paste?

I added to my .irbrc: IRB.conf[:PROMPT].reverse_merge!(:RAILS_ENV => {:PROMPT_I=>"#{current_app} #{rails_env} #{prompt} ", :PROMPT_N=>"#{current_app} #{rails_env} #{prompt} ", :PROMPT_S=>nil, :PROMPT_C=>"?> ", :RETURN=>"=> %s\n"})…
patrick
  • 9,290
  • 13
  • 61
  • 112
8
votes
1 answer

Can I open a rails console in read-only mode?

I'm used to interrogating my rails db via script/console. But in some instances I need to be exceptionally careful about not changing data, so I'd like to be able to open the console in a read-only mode. Is there any way to do this? Thanks!
brahn
  • 12,096
  • 11
  • 39
  • 49
8
votes
2 answers

Require command not working within bash irb on Snow Leopard

I am working on Zed Shaw's Learn Ruby the Hard Way Exercise 25 http://ruby.learncodethehardway.org/ex25.html When I navigate to the directory that holds the ruby file ex25.rb and launch IRB, I get these errors: Larson-2:~ larson$ cd…
Andrew Lauer Barinov
  • 5,694
  • 10
  • 59
  • 83