Skip to content

Instantly share code, notes, and snippets.

@e0da
Created July 26, 2013 18:38
Show Gist options
  • Select an option

  • Save e0da/6091209 to your computer and use it in GitHub Desktop.

Select an option

Save e0da/6091209 to your computer and use it in GitHub Desktop.
Ensure an argument is wrapped in an array
# Approach alpha is good if you know for certain that you're dealing with
# 1-dimensional arrays.
#
def alpha(parm)
parm = [parm].flatten
end
# Approach beta works if you need to support multi-dimensional arrays because it
# doesn't rely on #flatten.
#
def beta(parm)
parm = [parm] unless parm.is_a? Array
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment