Parent

Hash

Public Class Methods

[](*args) click to toggle source
# File lib/backports/1.8.7/hash.rb, line 7
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 == Backports.is_array?(arr)
    next unless (1..2).include? arr.size
    h[arr.at(0)] = arr.at(1)
  end
  h
end
constructor_without_key_value_pair_form(*args) click to toggle source
Alias for: []
try_convert(x) click to toggle source
# File lib/backports/1.9.1/hash.rb, line 4
def try_convert(x)
  Backports.try_convert(x, Hash, :to_hash)
end

Public Instance Methods

assoc(key) click to toggle source

Standard in Ruby 1.9. See official documentation

# File lib/backports/1.9.1/hash.rb, line 15
def assoc(key)
  val = fetch(key) do
    return find do |k, v|
      [k, v] if k == key
    end
  end
  [key, val]
end
default_proc=(proc) click to toggle source

Standard in Ruby 1.9. See official documentation

# File lib/backports/1.9.1/hash.rb, line 10
def default_proc=(proc)
  replace(Hash.new(&Backports.coerce_to(proc, Proc, :to_proc)).merge!(self))
end
eql?(other) click to toggle source

Ruby 1.8.6 doesn't define a Hash specific eql? method.

# File lib/backports/1.8.7/hash.rb, line 30
def eql?(other)
  other.is_a?(Hash) &&
    size == other.size &&
    all? do |key, value|
      other.fetch(key){return false}.eql?(value)
    end
end
hash() click to toggle source

Ruby 1.8.6 doesn't define a Hash specific hash method

# File lib/backports/1.8.7/hash.rb, line 21
def hash
  h = 0
  each do |key, value|
    h ^= key.hash ^ value.hash
  end
  h
end
keep_if() click to toggle source
# File lib/backports/1.9.2/hash.rb, line 2
def keep_if
  return to_enum(:keep_if) unless block_given?
  delete_if{|key, value| ! yield key, value}
end
rassoc(value) click to toggle source

Standard in Ruby 1.9. See official documentation

# File lib/backports/1.9.1/hash.rb, line 26
def rassoc(value)
  k = key(value)
  v = fetch(k){return nil}
  [k, fetch(k)] if k || v == value
end
reverse_merge(other_hash) click to toggle source

Standard in rails. See official documentation

# File lib/backports/rails/hash.rb, line 3
def reverse_merge(other_hash)
  other_hash.merge(self)
end
reverse_merge!(other_hash) click to toggle source

Standard in rails. See official documentation

# File lib/backports/rails/hash.rb, line 8
def reverse_merge!(other_hash)
  replace(reverse_merge(other_hash))
end
select!(&block) click to toggle source
# File lib/backports/1.9.2/hash.rb, line 7
def select!(&block)
  return to_enum(:select!) unless block_given?
  reject!{|key, value| ! yield key, value}
end
select_with_hash_return() click to toggle source
# File lib/backports/force/hash_select.rb, line 3
def select_with_hash_return
  return to_enum(:select) unless block_given?
  Hash[select_without_hash_return{|k, v| yield [k, v]}]
end
stringify_keys() click to toggle source

Standard in rails. See official documentation

# File lib/backports/rails/hash.rb, line 23
def stringify_keys
  Hash[map{|key,value| [key.to_s, value] }]
end
stringify_keys!() click to toggle source

Standard in rails. See official documentation

# File lib/backports/rails/hash.rb, line 28
def stringify_keys!
  self.replace(self.stringify_keys)
end
symbolize_keys() click to toggle source

Standard in rails. See official documentation

# File lib/backports/rails/hash.rb, line 13
def symbolize_keys
  Hash[map{|key,value| [(key.to_sym rescue key) || key, value] }]
end
symbolize_keys!() click to toggle source

Standard in rails. See official documentation

# File lib/backports/rails/hash.rb, line 18
def symbolize_keys!
  self.replace(self.symbolize_keys)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.