Skip to content

Instantly share code, notes, and snippets.

@ibrado
ibrado / flat.rb
Created June 10, 2018 14:01
Flatten arrays, with compact option
#!/usr/bin/ruby
# A function to flatten arrays, optionally removing any nil elements
#
# ==== Parameters
# * +val+ - a value expected to be an array
# * +compact+ - set to true to remove nil elements
#
def flat(val, compact = false)
if val.is_a?(Array)

Keybase proof

I hereby claim:

  • I am ibrado on github.
  • I am ibrado (https://keybase.io/ibrado) on keybase.
  • I have a public key whose fingerprint is 63A8 287D CC67 9437 0B50 E9FB 49B3 68CF F45C 06E9

To claim this, I am signing this object: