2

I am not sure this is a bug or a new feature of Ruby 2.6, but since performing the upgrade 2.3 --> 2.6, my IRB terminal does not behave as usual and cannot hide outputs anymore. Previously when I typed a semicolon, it would wait until receiving the next instruction without semicolon to run all the code and hide values with semicolons

2.6.3 :008 > 1 + 1
 => 2
2.6.3 :009 > 1 + 1;
 => 2 
2.6.3 :010 > (1 + 1);
 => 2
2.6.3 :011 > very_large_inspect_result;
 => [console keeps printing for ages)

Using ruby-2.6.3 [ x86_64 ] and the IRB terminal from rails-5.1.6

What can I do to hide the output from commands ? The goal is to avoid printing huge strings of inspect when returning a very large collection

EDIT : I could systematically add a 0 or something after the semicolons, but it feels cheap

2.6.3 :010 > (1 + 1); 0
 => 0

EDIT2 : what happened previously in Ruby 2.3.x :

irb(main):001:0> puts 1;
irb(main):002:0* puts 2;
irb(main):003:0* puts 3
1
2
3
=> nil
4
  • stackoverflow.com/questions/4678732/… Commented Aug 28, 2019 at 12:45
  • Pry suppresses output when adding a ; and generally offers some nice additions over irb. Commented Aug 28, 2019 at 13:23
  • You could also do this out = $stdout and $stdout = File.open(File::NULL,'w') then when you are done just set $stdout = out to reset the output stream. This is essentially like piping to "/dev/null" Commented Aug 28, 2019 at 14:12
  • @MichaelKohl trailing ; now works in newer versions Commented May 15, 2024 at 5:59

1 Answer 1

4

Run the below command in IRB terminal.

irb_context.echo = false
Sign up to request clarification or add additional context in comments.

3 Comments

This will be applied for all possibilities
Not sure but I think it will.
this does not work ? I have edited my question to give an example of what happened in RUby 2.3 before I upgraded to Ruby 2.6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.