Reputation: 4490
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
Upvotes: 3
Views: 372
Reputation: 13014
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.
Upvotes: 6