Just wondering. Is it possible to perform an early return from a block in Ruby? I'm noticing that if I use `return` from a block is jumps out of the containing method instead of the block. I guess if returns aren't possible, the alternative would be to just fully describe the logic in blocks and make sure the result is evaluated last on all codepaths...right?
ljarvis: True. Are early `return` 's just seldom used in Ruby because of the last-statement-is-the-return-value behavior?
elomatreb: Yeah...this is a thing in JS as well. But it's more because in earlier iterations of the language, folks couldn't decide how to handle background tasks, so some slow operations take a callback which is called with an optional error argument. So, first thing u do is inspect the error, and return immediately if something's wrong...then process the result of the slow operation.
elomatreb: Since this happens *a lot* folks just do an early return, and avoid the indenting.
elomatreb: And, not garbled enough to be unreadable :) thx for the insights.
So, `next` in blocks (but avoid early return) and `return` in actual functions. I guess blocks !== functions in Ruby, eh?
ropeney: If you talk to a hardcore functional programmer, you'll notice anger if you say that a routine the mutates data is a function.
Just sort of filling in some gaps in Ruby from a long time ago. I'm trying to use `system()` to run an external command, but want to (1) pass in an array of arguments...bypassing the shell and (2) hide all of the output. Based on the documentation, there are options for redirection, but how do I redirect to the bit-bucket in a platform neutral way?
havenwood: Yeah...I, for some reason, thought that this literally closed the file descriptor. If it did, the process would be hitting some issues trying to write to it. Ruby must be doing some sort of magic.