How to suppress the output of return value in IRB/Rails Console?
Asked Answered
O

4

38

An example is if I go into IRB and do the following:

jruby-1.6.7 :026 > puts [1,2,3,4,5]
1
2
3
4
5
=> nil 

Is there anyway to suppress the nil? The problem is if I put in a large data structure, it spams something an other irrelevant return respond. I'm more interested in seeing output from debug statements I run through a block and have to continually scroll up and look for the real data.

Officiate answered 14/4, 2012 at 2:32 Comment(3)
Perhaps try this: austinruby.com/2006/10/6/quieting-irb-s-return-valueConcentration
From the solutions below irb --simple-prompt --noecho is certainly your best and simplest bet.Frugal
Possible duplicate of How to suppress Rails console/irb outputsDibromide
L
63

If you just want to suppress long output once in a while, use ;0, like:

a = [*1..10000];0
# => 0

If you want to suppress it generally, use the ~/.irbrc file. The IRB.conf[:INSPECT_MODE] and IRB.conf[:PROMPT][your_prompt][:RETURN] control what is returned. You can figure out what your_prompt is by checking IRB.conf[:PROMPT_MODE]

Example:

IRB.conf[:PROMPT][:DEFAULT][:RETURN] = "" # suppress return value completely

You'll need to restart irb after changing the value.

Levitation answered 14/4, 2012 at 2:56 Comment(0)
Z
18

You can also supress the output with the following command as irb --simple-prompt --noecho.

Find the below:

@ubuntu:~$ irb --simple-prompt
>> puts "hi"
hi
=> nil
>> p "hi"
"hi"
=> "hi"
>> exit
@ubuntu:~$ irb --simple-prompt --noecho
>> puts "hi"
hi
>> p "hi"
"hi"
>> 

Hope you will be fine with it.

I am using ruby version as below :

@ubuntu:~$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
Zelma answered 15/2, 2013 at 22:4 Comment(0)
L
7

From @Tallboy dead link

To suppress the return value in Rails console, enter
conf.return_format = ""

Default (Print the return value)
conf.return_format = "=> %s\n"

Lactalbumin answered 26/3, 2015 at 9:43 Comment(0)
C
6

i run the following in irb:

irb_context.echo = false

e.g.

$ irb
> "foo"
=> "foo"
> irb_context.echo = false
> "foo"
>
Commissionaire answered 17/10, 2018 at 21:54 Comment(1)
Note that this can also be easily turned back on, e.g. irb_context.echo = false; "foo"; irb_context.echo = true, which can be handy for disabling return values only on certain code sections.Rusticate

© 2022 - 2024 — McMap. All rights reserved.