Question

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

Était-ce utile?

La solution

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.

Autres conseils

Add the --noecho flag.

How it works:

$ irb --noecho
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top