Skip to content

Instantly share code, notes, and snippets.

@thefotios
Created July 11, 2012 19:26
Show Gist options
  • Save thefotios/3092607 to your computer and use it in GitHub Desktop.
Save thefotios/3092607 to your computer and use it in GitHub Desktop.
Some awesome idiomatic Ruby functions

Check a variable against multiple functions

This runs all functions against a single variable. It will return true if any of the functions do. It rescues errors with false so we don't break in case you are expecting something, but end up with a nil.

functions = [:nil?,:empty?]
functions.map{|f| $variable.send(f) rescue false }.inject(:|)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment