Created
July 26, 2013 18:38
-
-
Save e0da/6091209 to your computer and use it in GitHub Desktop.
Ensure an argument is wrapped in an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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