Skip to content

Instantly share code, notes, and snippets.

@mernen
Created February 4, 2009 11:51
Show Gist options
  • Save mernen/58063 to your computer and use it in GitHub Desktop.
Save mernen/58063 to your computer and use it in GitHub Desktop.
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