Skip to content

Instantly share code, notes, and snippets.

@sebglazebrook
Last active August 29, 2015 14:10
Show Gist options
  • Save sebglazebrook/318e037781e1c2ab1d21 to your computer and use it in GitHub Desktop.
Save sebglazebrook/318e037781e1c2ab1d21 to your computer and use it in GitHub Desktop.
Differing between array like and hash like objects
# Came across an issue when working on a serializer/deserializer
# needed to know whether something was array like or hash like.
class Object
def array_like?
self.respond_to?(:each) && respond_to?(:at)
end
def hash_like?
self.respond_to?(:each) && !array_like?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment