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

I'll give you Erlang, but the Ruby solution is cheating rather.



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)


How is Ruby's method and different than Groovy or JavaScript? I think their all pretty neat. Goes to show that there is always more than one way to skin a list.


True. I guess built-in functions shouldn't count.




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

Search: