Created
February 4, 2009 11:51
-
-
Save mernen/58063 to your computer and use it in GitHub Desktop.
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
| def coerce_to_array(v) | |
| if v.IS_A?(Array) # internal test, not #is_a? method call | |
| v | |
| elsif v.respond_to?(:to_ary) # replace with to_a for 1.9 | |
| result = v.to_ary | |
| if result.IS_A?(Array) | |
| result | |
| else | |
| raise TypeError | |
| end | |
| else | |
| [v] | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment