Sha256: a3a19c0c23e4cf0ff45e03b4bffb0427d2984b25afca3cb451cf081fc1dfb05d

Contents?: true

Size: 715 Bytes

Versions: 2

Compression:

Stored size: 715 Bytes

Contents

class Hash
  # From the 'backports' gem
  # New Ruby 1.8.7+ constructor -- not documented, see redmine # 1385
  # <tt>Hash[[[:foo, :bar],[:hello, "world"]]] ==> {:foo => :bar, :hello => "world"}</tt>
  unless (Hash[[[:test, :test]]] rescue false)
    class << self
      alias_method :constructor_without_key_value_pair_form, :[]
      def [](*args)
        return constructor_without_key_value_pair_form(*args) unless args.length == 1 && args.first.is_a?(Array)
        h = {}
        args.first.each do |arr|
          next unless arr.respond_to? :to_ary
          arr = arr.to_ary
          next unless (1..2).include? arr.size
          h[arr.at(0)] = arr.at(1)
        end
        h
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
googleajax-1.0.1 lib/googleajax/extensions/hash.rb
googleajax-1.0.0 lib/googleajax/extensions/hash.rb