Have a look:

  module Enumerable

    # Take an associative array and unassociate it.
    #
    #   [[:a,1], [:b,2]].unassociate.to_a     #=> [:a, [1], :b, [2]]
    #   [[:a,1], [:b,2]].unassociate(1).to_a  #=> [:a, 1, :b, 2]
    #
    def unassociate(index = 1..-1)
      return to_enum(:unassociate, index) unless block_given?

      each do |v|
        case v
        when Array
          yield v[0]
          yield v[index]
        else
          yield v
          yield nil
        end
      end
    end

  end

Is it a good method name? Is 1..-1 the best default?

Other thoughts/ suggestions?


-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to