Skip to content

Instantly share code, notes, and snippets.

@jmmastey
Last active August 29, 2015 14:05
Show Gist options
  • Save jmmastey/6ae550cee8730cf4fbd9 to your computer and use it in GitHub Desktop.
Save jmmastey/6ae550cee8730cf4fbd9 to your computer and use it in GitHub Desktop.
Array(nil) # => []
Array(1) # => [1]
Array([3]) # => [3]
class ArrayLikeThing
def to_a
[1, 2, 3]
end
# defining to_ary is required for Array() casting to work.
alias :to_ary :to_a
end
thing = ArrayLikeThing.new
Array(thing) # => [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment