-
-
Save leejarvis/f5e78174b49e12d4af86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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