Hacker News new | comments | show | ask | jobs | submit login

Here's a better Ruby version:

    module Enumerable
      def custom_flatten
        inject([]) do |result, element|
          if element.respond_to?(:custom_flatten)
            result.concat(element.custom_flatten)
          else
            result.push(element)
          end
        end
      end
    end
Works on all Enumerables (Array, Hash, Set, etc)



Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: