The important part here
is the $stdout.tty? method call.
This uses the IO#tty? method
to determine if the output is a terminal
or a program.
It “dilutes” the text
only if the output is a terminal.
When we pipe the output to ruby,
it detects that the output isn’t a terminal
so it pipes the original text from fib.rb.

The more time I’ve spent
trying to understand Ruby,
the less magic it seems to have.
So it’s nice to come across something
that left me completely baffled
and left me thinking,
“how could that even work?”.

This was a perfect code demo
for a conference called “Keep Ruby Weird”.
That we have a conference with that name
is what makes the Ruby community so much fun. ;)

Hi, I’m Nithin Bekal.
I work at Shopify in Ottawa, Canada.
Previously, co-founder of
CrowdStudio.in and
WowMakers.
Ruby is my preferred programming language,
and the topic of most of my articles here,
but I'm also a big fan of Elixir.
Tweet to me at @nithinbekal.