Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Created June 1, 2015 21:23
Show Gist options
  • Save leejarvis/f5e78174b49e12d4af86 to your computer and use it in GitHub Desktop.
Save leejarvis/f5e78174b49e12d4af86 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
module Enumerable
def nested_count
count = 0
each do |e|
if e.respond_to?(:nested_count)
count += 1 + e.nested_count
end
end
count
end
end
p [[[[1,2,3]]]].nested_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment