RSS
 

Dica de Ruby #1 – abort

22 jan

Há algum tempo eu tenho estudado e praticado a linguagem Ruby. Desta forma, para registrar minhas descobertas vou postá-las como dicas neste blog.

A primeira dica é sobre escrever no stderr e interromper seu script quando acontece algo errado. Isto é uma prática comum dos hackers de UNIX.

Em Ruby existem muitas formas de se fazer algo e esta dica é um exemplo disto.

Então, ao invés de fazer isto:

STDERR.puts "Alguma coisa deu errado"
exit(1)

você pode fazer isto:

abort "Aguma coisa deu errado"

Para saber mais sobre o método abort, clique aqui.

É isso aí. ;-)

 

Ruby Tip #1 – abort

22 jan

For some time I have been studying and practicing the Ruby language. Thus, to register my discoveries I’ll post them as Ruby tips in this blog.

The first tip is about writing to stderr and quitting your script when something goes wrong. It’s a common practice for UNIX hackers do this.

In Ruby there is a lot of ways for doing something and this is one of the few examples.

So, instead of doing this:

STDERR.puts "Something gone wrong"
exit(1)

we can do this:

abort "Something gone wrong"

To know more about the abort method, click here.

That’s it. ;-)