Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress output of Enumerable::each in irb

Tags:

ruby

irb

The return value of Enumerable::each is the object that called each.

When I am inside irb this is really annoying since I get huge outputs.
Is it possible to suppress the return value of Enumerable::each in irb?

For example this

[1,2].each {|u| puts "hey"}

output this

>> [1,2].each {|u| puts "hey"}
hey
hey
=> [1, 2]

I want to get rid of the last line

like image 873
mottalrd Avatar asked Nov 27 '25 02:11

mottalrd


2 Answers

That is simple.

Just add a semicolon(;) at end of the statement/expression in Ruby whose return value you don't want to see and also add nil.

Make it:

[1,2].each {|u| puts "hey"}; nil

But please note that there is no reason to suppress the irb output(except when the return value is too large/lot of text); it helps a lot in debugging and to know what exactly is going on in the function.

like image 114
kiddorails Avatar answered Nov 28 '25 15:11

kiddorails


Add the --noecho flag.

How it works:

$ irb --noecho
like image 27
user3490179 Avatar answered Nov 28 '25 15:11

user3490179



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!