7

Is it possible to escape that effect when assigning to a value:

irb(main):584:0>a = true
=>true
irb(main):584:0>

I have a code that has lots of assignings and when I am trying to test it I can not see the result because of all these returned values:

true
false
true
false
true
true
..
1
  • Wrap this code in proc object? Commented Dec 22, 2013 at 17:19

3 Answers 3

16

You can start the irb or console attaching the --noecho option.

$ irb --noecho
2.0.0p353 :001 > true
2.0.0p353 :002 > 

Otherwise, if the console was started by another process, simply set conf.echo = false

$ irb 
2.0.0p353 :001 > true
 => true 
2.0.0p353 :002 > conf.echo = false
2.0.0p353 :004 > true
2.0.0p353 :005 > 
Sign up to request clarification or add additional context in comments.

2 Comments

I configured it aditionally with the conf.echo but it keeps on returning these values. I have a module that has few class and modules inside of it and in the end of the model I make instances of the nested class and it generates those values. But thanks anyway.
Type (or print out) conf and make sure that it prints out conf.echo=false. It also needs to be the first statement as soon as you start irb.
10

Stick a semi-colon behind the command and it doesn't print, works for both pry and irb

PRY

[1] pry(main)> a = true
=> true
[2] pry(main)> a = true;
[3] pry(main)>

IRB

2.0.0p247 :001 > a = true
 => true
2.0.0p247 :002 > a = true;
2.0.0p247 :003 >

1 Comment

The IRB version does not do what you think it does. Try with this for example: puts "hi";. Your understanding of Pry behaviour is correct though.
0

None of the answers above could work for my setup so I ended up just making a little helper and declared things out of scope. Quick and dirty, but gets the job done:

def quiet(&block)
  yield
  nil
end

foo = nil
quiet { foo = 'long' * 1000 }

Comments

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.