# Suppressing printing of evaluated expressions in irb

**URL:** <https://www.ruby-forum.com/t/suppressing-printing-of-evaluated-expressions-in-irb/55424>\
**Category:** Ruby\
**Created:** [March 21, 2006, 12:13am UTC](https://www.ruby-forum.com/t/suppressing-printing-of-evaluated-expressions-in-irb/55424 "2006-03-21T00:13:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![teddio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b3f665/32.png) [@teddio](https://www.ruby-forum.com/u/teddio)\
**Post date:** [March 21, 2006, 12:13am UTC](https://www.ruby-forum.com/t/suppressing-printing-of-evaluated-expressions-in-irb/55424/1 "2006-03-21T00:13:54Z")

</div>

I’ve looked all over, but I can’t figure out how to suppress the  
printing of evaluated expressions in irb. Ordinarily, this is no  
problem:

irb(main):001:0\> a = []  
=\> []

But what if the thing returned is huge?

irb(main):001:0\> b = function\_returning\_something\_huge

In Python, the interpreter suppresses the printing of the expression if  
there is assignment, but not otherwise:

> > > a = []  
> > > a  
> > > []
> 
> > > b = function\_returning\_something\_huge()  
> > > b  
> > > \<disaster, but I asked for it!\>

How do I get the same or similar behavior in irb?

Thanks in advance,

Michael

---

<div class="post-metadata">

**Author:** ![teddio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b3f665/32.png) [@teddio](https://www.ruby-forum.com/u/teddio)\
**Post date:** [March 21, 2006, 1:25am UTC](https://www.ruby-forum.com/t/suppressing-printing-of-evaluated-expressions-in-irb/55424/2 "2006-03-21T01:25:31Z")

</div>

On Mar 20, 2006, at 3:13 PM, Michael H. wrote:

> 

In irb, enter `conf.return_format = ""` That’ll turn off all  
printing of evaluations in irb, which means you have to use `puts` if  
you want to see any results, but it’ll avoid your disasters.

You can add 2 methods to your .irbrc if you like, one that clears the  
formatting with the line I gave, and one that sets it back to normal  
(the default is “=\> %s\n”), so that you can switch back and forth  
between the two modes easily.

There may be a better solution, but this is all I came up with.  
Still, I hope it helps.

Tim

---

<div class="post-metadata">

**Author:** ![teddio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b3f665/32.png) [@teddio](https://www.ruby-forum.com/u/teddio)\
**Post date:** [March 21, 2006, 1:37am UTC](https://www.ruby-forum.com/t/suppressing-printing-of-evaluated-expressions-in-irb/55424/3 "2006-03-21T01:37:04Z")

</div>

On Mar 20, 2006, at 4:25 PM, Timothy B. wrote:

> There may be a better solution, but this is all I came up with.

There is another solution, that of course I realize after I send out  
the message. You can set conf.return\_format to “=\> %0.100s\n”, where  
the number after the . (in this case 100), is the maximum number of  
characters you want printed to the screen.

Tim

---

<div class="post-metadata">

**Author:** ![teddio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b3f665/32.png) [@teddio](https://www.ruby-forum.com/u/teddio)\
**Post date:** [March 21, 2006, 2:20am UTC](https://www.ruby-forum.com/t/suppressing-printing-of-evaluated-expressions-in-irb/55424/4 "2006-03-21T02:20:28Z")

</div>

On 3/20/06, Michael H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

If you want to suppress printing for just one line, try appending ‘;0’  
to the end of the command:

irb(main):001:0\> b = function\_returning\_something\_huge;0  
=\> 0

---

<div class="post-metadata">

**Author:** ![teddio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b3f665/32.png) [@teddio](https://www.ruby-forum.com/u/teddio)\
**Post date:** [March 21, 2006, 2:11am UTC](https://www.ruby-forum.com/t/suppressing-printing-of-evaluated-expressions-in-irb/55424/5 "2006-03-21T02:11:49Z")

</div>

Hello everyone,

I’m trying to keep a thread alive after exiting a method. The pseudo-  
code is as follows:

class A

```
def start
	@mainThread = Thread.new {
		oneThread = Thread.new {
			# do some stuff
		}
		twoThread = Thread.new {
			# do some other stuff
		}
		oneThread.join
		twoThread.join
	}
end

```

end

aObject = A.new  
aObject.start

The problem is that since there is no :join call on @mainThread, it  
is killed (and hence oneThread, and twoThread as well) once control  
ends in :start. This is perfectly valid, of course, but I would like  
@mainThread to stay alive after control in :start ends. Is there any  
way to do this? Thanks

Nate

---

<div class="post-metadata">

**Author:** ![teddio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b3f665/32.png) [@teddio](https://www.ruby-forum.com/u/teddio)\
**Post date:** [March 28, 2006, 1:14am UTC](https://www.ruby-forum.com/t/suppressing-printing-of-evaluated-expressions-in-irb/55424/6 "2006-03-28T01:14:08Z")

</div>

Thanks for your help. Tim’s suggestions are nice, but I’d prefer to be  
able to make the print/no-print decision on the fly, on a per-statement  
basis. On these grounds, Caleb’s suggestion meets my needs best. I  
had actually tried using a semicolon, but of course irb then just waits  
for the next statement. Putting a 0 (or anything else) is a bit of a  
kludge compared to the Python interpreter’s convention, but it gets the  
job done.

Thanks,

Michael

---

<div class="post-metadata">

**Author:** ![teddio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b3f665/32.png) [@teddio](https://www.ruby-forum.com/u/teddio)\
**Post date:** [March 21, 2006, 2:51am UTC](https://www.ruby-forum.com/t/suppressing-printing-of-evaluated-expressions-in-irb/55424/7 "2006-03-21T02:51:04Z")

</div>

Nate Smith wrote:

> ```
> # do some stuff
> 
> ```
> 
> aObject = A.new

Is you program exiting after aObject.start? Then maybe you want to do  
@mainThread.join at that point?

The @mainThread should still be alive, until the program exits, unless  
it has suffered an exception.

Do you have Thread.abort\_on\_exception = true?
