What's the Difference Between the Ruby Irb Prompt Modes

What's the difference between the ruby irb prompt modes?

The answer to those questions lie in IRB.conf[:PROMPT] which is a hash whose keys are the different prompts and whose values are the configurations for each prompt. Read this to a understand a prompt's configuration.

The difference between null and xmp is that xmp displays a result indented with an arrow:

$ irb --prompt xmp -f
2**10
==>1024

while null doesn't indent or display the arrow:

$ irb --prompt null -f
2**10
1024

You should be able to answer your second question once you read the above link and understand that prompts have different modes and different configurations for them.

What does irb --simple-prompt do?

It gives you a simpler prompt (lol). No ruby version and no line number.

Example using irb --simple-prompt:

user: $ irb --simple-prompt
>>

Example using irb:

user: $ irb
2.0.0-p353 :001 >

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

$ irb --help
Usage: irb.rb [options] [programfile] [arguments]
--prompt prompt-mode
--prompt-mode prompt-mode
Switch prompt mode. Pre-defined prompt modes are
`default', `simple', `xmp' and `inf-ruby'

$ irb --prompt inf-ruby
irb(main):001:0>

Difference between quit and exit in irb?

It seems so.

method(:quit).owner    #=> IRB::ExtendCommandBundle
method(:exit).owner #=> IRB::ExtendCommandBundle
method(:exit).source_location
#=> ["/usr/local/lib/ruby/2.2.0/irb/extend-command.rb", 28]
method(:quit).source_location
#=> ["/usr/local/lib/ruby/2.2.0/irb/extend-command.rb", 28]
method(:exit) == method(:quit) #=> true

Copy paste from irb excluding prompt at start of line?

You can hold the ⌥ Option key and drag for a rectangular selection:

You can also customize IRB's prompt. Here's an example of the built-in --noprompt option which provides a blank prompt:


irb command line prefix remove

You can edit your ~/.irbrc file to change the prompt (command line prefix). See this answer for an example. You could put this in there to start:

IRB.conf[:PROMPT][:CUSTOM] = {:PROMPT_I => ">> "}
IRB.conf[:PROMPT_MODE] = :CUSTOM
IRB.conf[:AUTO_INDENT] = true

.irbrc is a Ruby script that irb runs when it starts up that lets you configure your prompt.

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

Here's a quick hack to get the working dir. It's sort of fragile, but it worked on ruby 1.8.7 and 1.9.2.

Set your prompt string to something like this:

"%N(%m):%03n:%i %~> ".tap {|s| def s.dup; gsub('%~', Dir.pwd); end }

The "%~" directive is not understood by irb itself, so I used it to do the replacement. This hack relies on the fact that irb calls dup to generate the prompt.

missing '=' in ruby irb results

try

irb --prompt default

or

irb --prompt inf-ruby --readline

or this after irb starts

conf.prompt_c="%N(%m):%03n:%i* "
conf.prompt_i="%N(%m):%03n:%i> "
conf.prompt_mode=:DEFAULT
conf.prompt_n="%N(%m):%03n:%i> "
conf.prompt_s="%N(%m):%03n:%i%l "

also check irb --help it has some great help use that :)

Why is the --simple-prompt command not working?

You seem to be confused about passing flags to commands vs issuing statements in a REPL.

To start irb with the --simple-prompt option enabled, pass it in like so:

$ irb --simple-prompt
>>

Then you should be able to execute Ruby code.

>> puts "hello world!"
hello world!
=> nil
>>


Related Topics



Leave a reply



Submit