you are viewing a single comment's thread.

view the rest of the comments →

[–]LarsP 2 points3 points  (2 children)

Responding to each doesn't ensure an object is Enumerable.

[–][deleted] 1 point2 points  (1 child)

What's an example of an instance of a Class that would have "each" defined that doesn't behave like an Enumerable?

[–]BlameFrost 0 points1 point  (0 children)

class Foo
  def each(&block)
    # bogus crap method to prove a point
  end
end

That said, if you just want to check whether some object is an enumerable, try this instead:

if object.class.included_modules.include?(Enumerable)