With semicolons in IRB or PRY no result printing happens

Semicolons aren’t needed to end statements in Ruby. That’s same with IRB or PRY. So i’v never tried it.

One day i accidentally wrote semicolon at the end of my PRY statement. What happend?:

Noticed how nothing was printed after second line? Normally you would get another => "Fred" line. With semicolon at the end no printing happens.

When it’s actually usefull?

I work on a Rails project which uses PostgreSQL a lot. Sometimes when debugging i fire custom SQLs through ActiveRecord like this:

conn = ActiveRecord::Base.connection
conn.execute('select 1;')

The thing is when i assign connection into conn variable whole screen gets littered with connection info:

ActiveRecord connection

With semicolon at the end nothing like this happens and i don’t lose my context. :)


About me

Hi, i'm Premysl Donat and this is a place where i share things i find interesting.

This is my picture:

Premysl Donat at Balaton lake

I'm a web developer and i work at UOL. I also have a tiny company named Imagine Anything under which i run few side projects. Imagine has a beautiful logo so you better check it out!

I release all of my code under MIT license and it's freely available at Github.

Have a good one, Premek

Follow @Masa331