matsuda
12/13/2010 - 2:27 AM

Hashの値もflattenする

Hashの値もflattenする

class Array
  def flatten_with_hash
    inject([]){ |r, h|
      if h.is_a?(Hash)
        r << h.keys.flatten_with_hash
        r << h.values.flatten_with_hash
      else
        r << h
      end
      r
    }.flatten
  end
end