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
5
votes
2 answers

Strange irb behaviour, listing content current directory

When I paste this code in irb prompt I get listing of current directory after line if true. def some_method() if true raise StandardError end end Example of output: irb(main):151:0> def some_method() irb(main):152:1>…
XoR
  • 2,556
  • 4
  • 17
  • 15
5
votes
1 answer

.irbrc doesn't execute after installing RBEnv

I just changed over from RVM to RBEnv (+ruby-build). I have a custom .irbrc file, but after the rbenv install, it doesn't seem to execute it. This on OS X Lion. I have updated .bash_profile with: export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv…
Ben Woodall
  • 1,264
  • 9
  • 7
5
votes
3 answers

How can a Ruby class detect the process name that runs it?

I am using delayed_jobs to run Ruby classes, how can the Ruby detect the name (command) of the process that is running it? any thoughts?
Ran
  • 3,455
  • 12
  • 47
  • 60
5
votes
5 answers

Is it possible to configure the IRB prompt to change dynamically?

I'd like to navigate around the filesystem in IRB and have the prompt change to reflect the current working directory, but I can't figure out how to make the prompt update after each command. Ultimately I'd like to use IRB in day to day work a lot…
Julian Mann
  • 6,256
  • 5
  • 31
  • 43
5
votes
3 answers

Ruby - how to reload a file with changes in IRB or PRY?

I go into irb and require a file irb> require_relative 'prime' irb> true This file contains the following code: def is_prime? num (2..num-1).each do |div_by| if num % div_by == 0 return false end end true end requiring the…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
5
votes
2 answers

Why does irb insert control characters into my reverse-interactive-search buffer?

If I do a reverse interactive search in irb and then enter a control character (arrow keys are the only ones I've seen this with actually). So I start with this session: $ irb >> print "hello" hello then enter ^r, h $ irb >> print…
John Bachir
  • 22,495
  • 29
  • 154
  • 227
5
votes
1 answer

How make `reverse-i-search` history use fzf in irb or pry console

I have looked around, can not find anyway to use fzf to search history in irb or pry console. Is there any way make it?
Fangxing
  • 5,716
  • 2
  • 49
  • 53
5
votes
2 answers

Customising IRB console for gem

I'd like to extend the default console application that is built as standard with bundle gem by applying some of the IRB config options. Looking at the documentation, I can see that it should be possible for instance to change the prompt, and this…
Neil Slater
  • 26,512
  • 6
  • 76
  • 94
5
votes
3 answers

How to run script before every Rails console invocation?

I'm pretty tired of writing this line every time I want to open the Rails console: irb(main):001:0> ActsAsTenant.current_tenant = User.find(1).account Is there any way to run command/script before every "rails c"/"irb" invocation? Thanks in…
shunter
  • 139
  • 2
  • 9
5
votes
3 answers

Ruby - return an array in random order

What is the easiest way to return an array in random order in Ruby? Anything that is nice and short that can be used in an IRB session like [1,2,3,4,5].random() # or random_sort([1,2,3,4,5])
BuddyJoe
  • 69,735
  • 114
  • 291
  • 466
5
votes
1 answer

IRB.start not starting

I have some code that runs IRB.start (from inside a gem) However, I get this error in magic-file.rb "No such file or directory @ rb_sysopen - console" /Users/you/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/irb/magic-file.rb:7:in `initialize': No such file…
Some Guy
  • 12,768
  • 22
  • 58
  • 86
5
votes
1 answer

Problems installing rdoc, irb, bluecloth, chronic on fedora 12

What do these errors mean? [root@localhost config]# gem install bluecloth Building native extensions. This could take a while... ERROR: Error installing bluecloth: ERROR: Failed to build gem native extension. /usr/bin/ruby extconf.rb can't…
Vineeth Pradhan
  • 8,201
  • 7
  • 33
  • 34
5
votes
3 answers

PRY or IRB - reload class and forget deleted functionality

If you change a file then re-load it in pry or irb, it seems to pick up any NEW functionality you've added to that class, but doesn't forget about OLD functionality you've deleted from that class. Steps to reproduce: Create a class with a single…
joshua.paling
  • 13,762
  • 4
  • 45
  • 60
5
votes
3 answers

Rails check if IRB console or webpage

In my model I would like to check if the app is running inside IRB consol or as a website? class MyModel < ActiveRecord::Base def xmethod if !isIRBconsol self.user_id = UserSession.find.user.id end end end
xpepermint
  • 35,055
  • 30
  • 109
  • 163
5
votes
2 answers

Does Ruby use $stdout for writing the output of puts and return?

I want to know the output stream being used by Ruby to print these things at the command-line: irb(main):001:0> a="test" => "test" irb(main):002:0> puts a test => nil irb(main):003:0> a => "test" Is $stdout used for irb(main):002:0> and…
Keyur Shah
  • 81
  • 1
  • 6