vendor/rails/activesupport/lib/active_support/ordered_hash.rb in radiant-0.8.0 vs vendor/rails/activesupport/lib/active_support/ordered_hash.rb in radiant-0.8.1

- old
+ new

@@ -8,10 +8,34 @@ def initialize(*args, &block) super @keys = [] end + def self.[](*args) + ordered_hash = new + + if (args.length == 1 && args.first.is_a?(Array)) + args.first.each do |key_value_pair| + next unless (key_value_pair.is_a?(Array)) + ordered_hash[key_value_pair[0]] = key_value_pair[1] + end + + return ordered_hash + end + + unless (args.size % 2 == 0) + raise ArgumentError.new("odd number of arguments for Hash") + end + + args.each_with_index do |val, ind| + next if (ind % 2 != 0) + ordered_hash[val] = args[ind + 1] + end + + ordered_hash + end + def initialize_copy(other) super # make a deep copy of keys @keys = other.keys end @@ -53,9 +77,13 @@ @keys.collect { |key| self[key] } end def to_hash self + end + + def to_a + @keys.map { |key| [ key, self[key] ] } end def each_key @keys.each { |key| yield key } end