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

Ruby 3 IRB home end and ctrl-u not working

I've recently started using Ruby 3 more and it seems the home key (to take me to the beginning of the line) the end key (end of the line) and ctrl-u (clear the line) aren't working. I'm running Arch Linux with Ruby 3.1.1p18 and a zsh shell. The keys…
KNejad
  • 2,376
  • 2
  • 14
  • 26
6
votes
1 answer

File.open and blocks in Ruby 1.8.7

I'm pretty new to ruby and I'm currently reading the Pickaxe book to get familiar with everything. I came across the File.open section where it discusses taking a block as a parameter to a File.open call then guaranteeing that the file is closed. …
OldTroll
  • 773
  • 6
  • 22
6
votes
1 answer

loading documents on IRB ruby

I am trying to load a file into IRB. I have the file saved on my desktop titled "Ruby.rb" How do i load the file into IRB? I have tried using both, 'load "Ruby.rb"', 'load "Ruby"' and 'require "Ruby.rb". these documents are on my desktop, is there…
jamal andrews
  • 63
  • 1
  • 4
6
votes
3 answers

word boundaries in irb

I'm using Terminal on Snow Leopard. At the command line, if I've typed foo.bar.baz.bang.quuz.quux, when i tap option-B, it moves the cursor backward word by word -- stopping at every period, because it considers a period to be a word boundary.…
Lawrence
  • 10,142
  • 5
  • 39
  • 51
6
votes
1 answer

Is /etc/irbrc installed by OS X? Does irb read it?

While investigating an issue with irb on my Mac (OS X 10.11.5) I noticed /etc/irbrc. The first few lines follow: # Some default enhancements/settings for IRB, based on # http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks unless defined?…
Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
6
votes
2 answers

Rails irb default directory

I'm trying to include a source code file when I run irb but irb is unable to find it. For example, say I am in the following directory in terminal: /dan/rubyapp/ Assume I have a file named "firstapp.rb" in /dan/rubyapp/ I startup irb and from the…
iljkj
  • 779
  • 1
  • 9
  • 13
6
votes
3 answers

Singleton class and instance variables

Why does the instance_variables method not show @var_one against the variable a? a = Object.new def a.my_eval; yield end a.my_eval { @var_one = 1 } a.instance_variables # => [] instance_variables # => [@var_one]
mhaseeb
  • 1,739
  • 2
  • 12
  • 24
6
votes
2 answers

'script/console test' with spork and rspec not loading the whole environment?

I'm trying to load up console to interact with some of my rspec mocking helpers. I expected that running script/console test would load an env similar to when I run spec. However, this doesn't appear to be the case. It looks like spec_helper is…
Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173
6
votes
5 answers

IRb: how to start an interactive ruby session with pre-loaded classes

As I am going through my journey by adopting the Ruby language, I spend a lot of time inside IRb. It's just fantastic! But, as I am not very aware of it's capabilities, and still a “nubby” with Ruby, I would like to know the following: How can I…
Shyam
  • 2,357
  • 8
  • 32
  • 44
6
votes
1 answer

How to experiment with rspec from within irb

For example, I want to say b = double("book") in irb and play with the result. In irb if I say require 'rspec' b = double("book") I get an error. Ideas?
pitosalas
  • 10,286
  • 12
  • 72
  • 120
6
votes
1 answer

IRB - Ruby 1.9.x hash syntax: {if: true} is not equal to {:if => true}

Long story short, I was writing a method that included an options argument, that will do certain stuff if the value for the key :if, evaluated to true. When I trying the hash in IRB using the new syntax I got a syntax error in IRB, the prompt stays…
Leonel Galán
  • 6,993
  • 2
  • 41
  • 60
6
votes
5 answers

How to incorporate Interactive Ruby into my development process?

I am trying to find a better way to integrate IRB with my normal ruby devleopment. Currently I rarely use IRB with my code. I only use it to verify syntax or to try something small. I know I can load my own code into ruby as a require…
Jeremy Mack
  • 4,987
  • 2
  • 25
  • 22
6
votes
3 answers

Using ice_cube Ruby gem in IRB

I'm trying to use a Ruby gem called ice_cube in IRB, but it doesn't work: [~]$ rvm gemset create ice 'ice' gemset created (/home/joe/.rvm/gems/ruby-1.9.2-p320@ice). [~]$ rvm gemset use ice Using ruby-1.9.2-p320 with gemset ice [~]$ gem install…
Asher Walther
  • 1,327
  • 2
  • 9
  • 13
6
votes
8 answers

Can I repeat command in irb?

Is there an easy way to repeat a previous command in Ruby irb? I wish to have something like using exclamation mark (!) in Unix. Thank you.
Robert A Henru
  • 2,222
  • 4
  • 21
  • 25
6
votes
4 answers

How to print a string with a backward slash in Ruby

I have a string str = "xyz\123" and I want to print it as is. The IRB is giving me an unexpected output. Please find the same below:- 1.9.2p290 :003 > str = "xyz\123" => "xyzS" 1.9.2p290 :004 > Any ideas on how can I get IRB to print the…
boddhisattva
  • 6,908
  • 11
  • 48
  • 72