Class Hash
In: lib/backports/1.8.7/hash.rb
lib/backports/1.9.1/hash.rb
lib/backports/1.9.2/hash.rb
lib/backports/force/hash_select.rb
lib/backports/rails/hash.rb
Parent: Object

Methods

External Aliases

[] -> constructor_without_key_value_pair_form
key -> self

Public Class methods

[Source]

    # File lib/backports/1.8.7/hash.rb, line 7
 7:       def [](*args)
 8:         return constructor_without_key_value_pair_form(*args) unless args.length == 1 && args.first.is_a?(Array)
 9:         h = {}
10:         args.first.each do |arr|
11:           next unless arr.respond_to? :to_ary
12:           arr = arr.to_ary
13:           next unless (1..2).include? arr.size
14:           h[arr.at(0)] = arr.at(1)
15:         end
16:         h
17:       end

[Source]

   # File lib/backports/1.9.1/hash.rb, line 4
4:     def try_convert(x)
5:       Backports.try_convert(x, Hash, :to_hash)
6:     end

Public Instance methods

Standard in Ruby 1.9. See official documentation

[Source]

    # File lib/backports/1.9.1/hash.rb, line 15
15:   def assoc(key)
16:     val = fetch(key) do
17:       return find do |k, v|
18:         [k, v] if k == key
19:       end
20:     end
21:     [key, val]
22:   end

Standard in Ruby 1.9. See official documentation

[Source]

    # File lib/backports/1.9.1/hash.rb, line 10
10:   def default_proc=(proc)
11:     replace(Hash.new(&Backports.coerce_to(proc, Proc, :to_proc)).merge!(self))
12:   end

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

[Source]

    # File lib/backports/1.8.7/hash.rb, line 31
31:   def eql?(other)
32:     other.is_a?(Hash) &&
33:       size == other.size &&
34:       all? do |key, value|
35:         other.fetch(key){return false}.eql?(value)
36:       end
37:   end

Ruby 1.8.6 doesn‘t define a Hash specific hash method

[Source]

    # File lib/backports/1.8.7/hash.rb, line 22
22:   def hash
23:     h = 0
24:     each do |key, value|
25:       h ^= key.hash ^ value.hash
26:     end
27:     h
28:   end

[Source]

   # File lib/backports/1.9.2/hash.rb, line 2
2:   def keep_if
3:     return to_enum(:keep_if) unless block_given?
4:     delete_if{|key, value| ! yield key, value}
5:   end

Standard in Ruby 1.9. See official documentation

[Source]

    # File lib/backports/1.9.1/hash.rb, line 26
26:   def rassoc(value)
27:     k = key(value)
28:     v = fetch(k){return nil}
29:     [k, fetch(k)] if k || v == value
30:   end

Standard in rails. See official documentation

[Source]

   # File lib/backports/rails/hash.rb, line 3
3:   def reverse_merge(other_hash)
4:     other_hash.merge(self)
5:   end

Standard in rails. See official documentation

[Source]

    # File lib/backports/rails/hash.rb, line 8
 8:   def reverse_merge!(other_hash)
 9:     replace(reverse_merge(other_hash))
10:   end

[Source]

    # File lib/backports/1.9.2/hash.rb, line 7
 7:   def select!(&block)
 8:     return to_enum(:select!) unless block_given?
 9:     reject!{|key, value| ! yield key, value}
10:   end

[Source]

   # File lib/backports/force/hash_select.rb, line 3
3:     def select_with_hash_return
4:       return to_enum(:select) unless block_given?
5:       Hash[select_without_hash_return{|k, v| yield [k, v]}]
6:     end

Standard in rails. See official documentation

[Source]

    # File lib/backports/rails/hash.rb, line 23
23:   def stringify_keys
24:     Hash[map{|key,value| [key.to_s, value] }]
25:   end

Standard in rails. See official documentation

[Source]

    # File lib/backports/rails/hash.rb, line 28
28:   def stringify_keys!
29:     self.replace(self.stringify_keys)
30:   end

Standard in rails. See official documentation

[Source]

    # File lib/backports/rails/hash.rb, line 13
13:   def symbolize_keys
14:     Hash[map{|key,value| [(key.to_sym rescue key) || key, value] }]
15:   end

Standard in rails. See official documentation

[Source]

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

[Validate]