Ruby Shortcuts

I sometimes stumble upon little snippets of ruby code that can replace longer loops. Like this one:


which eliminates all empty strings from an array of strings (does not work for Fixnum), which is quite handy following a “split” operation.

Another one is this:


which sums up all elements in an array and also works for strings.