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

Why does Iconv work different in irb and the Ruby interpreter?

I have to convert Latin chars like éáéíóúÀÉÍÓÚ etc., into a string to similar ones without special accents or wired symbols: é -> e è -> e Ä -> A I have a file named "test.rb": require 'iconv' puts Iconv.iconv("ASCII//translit", "utf-8",…
zambotn
  • 735
  • 1
  • 7
  • 20
4
votes
2 answers

At runtime, How to check from where a module or class is loaded from?

I have a legacy rails app with a lot of funny (for useless) modules and classes in the global namespace. I want to know from which files or gems they have been required using rails c. I know it exists for methods : .source_location,__line__,__file__…
Hartator
  • 5,029
  • 4
  • 43
  • 73
4
votes
1 answer

Why won't IRB work after I mistyped a string?

I started to learn Ruby using IRB and wrote the wrong code below: irb(main):001:0>"amefurashi".delete(aiueo") I noticed it was missing a double-quote mark, and the prompt changed to: irb(main):002:1" I wrote the correct…
Kotaro Ezawa
  • 1,509
  • 3
  • 13
  • 11
4
votes
2 answers

Rails 7 IRB console inserts escape key instead of execute delete command

I am using Mac OS and since latest rails version the delete key does not work anymore. ❯ rails -v Rails 7.0.4 ❯ ruby -v ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21] When I hit delete instead of removing the char and the current…
YvesR
  • 5,922
  • 6
  • 43
  • 70
4
votes
0 answers

Ruby: method argument default value

Let's see an example ruby-1.9.2-p180 :001 > class Demo ruby-1.9.2-p180 :002?> def self.class_method1(a,b=25) ruby-1.9.2-p180 :003?> return a + b ruby-1.9.2-p180 :004?> end ruby-1.9.2-p180 :005?> end ruby-1.9.2-p180 :007 > m =…
Fivell
  • 11,829
  • 3
  • 61
  • 99
4
votes
2 answers

How can I add a new line in Ruby 2.7+ IRB multiline edit mode?

Ruby 2.7 introduced an update to IRB that allows multiline editing. How can I add a new line into a multiline method to inject code between two previous statements? E.g. 2.7.1 :019 > while session = server.accept 2.7.1 :020 > session.puts "Hello…
Aaron
  • 13,349
  • 11
  • 66
  • 105
4
votes
1 answer

Why do I get undefined method `mktmpdir' for Dir:Class in irb using Ruby 2.6.3?

https://ruby-doc.org/stdlib-2.6.3/libdoc/tmpdir/rdoc/Dir.html contains a description about the mktmpdir method of the Dir class. mktmpdir(prefix_suffix=nil, *rest) ::mktmpdir creates a temporary directory. An app uses it with no error but why it…
Christian
  • 4,902
  • 4
  • 24
  • 42
4
votes
1 answer

Why is my top-level method public (as opposed to private) on all classes when I declare it in IRB?

I'm currently reading "The Well-Grounded Rubyist", and on page 196 I see the following: Suppose you define a method at the top level: def talk puts "Hello" end .... A method that you define at the top level is stored as a private instance…
Richie Thomas
  • 3,073
  • 4
  • 32
  • 55
4
votes
3 answers

How do I get the "irb(main):001:0>" prompt instead of ">>"

Ruby is preinstalled on my Mac and so I wanted to have a look at it. First thing I noticed, is that irb prompts >> instead of irb(main):001:0>. I can't find anything on how to change this with Google because everyone is using irb(main):001:0> in…
Christian
  • 1,027
  • 1
  • 13
  • 26
4
votes
1 answer

Rails console slow tab completion?

Running arch, when developing rails the console's tab completion for everything is incredibly slow. Even if the list it returns is inherently small. User.n for instance shouldn't return a horrid number of options, but it will basically halt for…
Jeremy
  • 645
  • 7
  • 19
4
votes
2 answers

Ruby Equivalent of Python "_"

In Python, you can use the _ field to grab the last computed value. That's really useful in IDLE. Does Ruby have an equivalent for IRB? An example from Python: >>> 2 + 2 4 >>> _ 4 >>> "Me " + "You" 'Me You' >>> _ 'Me You'
Mike
  • 19,267
  • 11
  • 56
  • 72
4
votes
1 answer

rails 5: rails c doesn't show line number on error

I'm running rails 5, upgraded from 4.2.x In the console and when running methods that fail, the error doesn't show the line number, I only get to see: Traceback (most recent call last): NoMethodError (undefined method `[]' for nil:NilClass) I made…
JUlinder
  • 995
  • 1
  • 8
  • 19
4
votes
2 answers

How to avoid 'no such file to load -- map_by_method' script/console with bundler?

I am running rails 2.3.10 with bundler. I use rvm, in global gemsets usually I put the gems useful for the irb. By default I had these there: map_by_method, what_methods, ap, net-http-spy, hirb, looksee, pp, wirble. When I start irb, the gems it…
fifigyuri
  • 5,771
  • 8
  • 30
  • 50
4
votes
1 answer

Why doesn't Date.today work on Ruby console (irb)?

In irb I am trying Date.today and it fails. I was originally trying to do: Date.today.strftime "%b %d, '%y"
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
4
votes
3 answers

How to get irb and rails console to work properly in gitbash?

I'm using gitbash ver 2.9.0, 64-bit, on Windows 7. It uses mintty version 2.0.3. The gitbash shell most of the time seems to work fine. You can use the arrow keys, etc, as with any bash shell and they perform as expected, being able to scroll…
lurker
  • 56,987
  • 9
  • 69
  • 103