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 |
[] | -> | constructor_without_key_value_pair_form |
key | -> | self |
# 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
# 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
Standard in Ruby 1.9. See official documentation
# 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
# 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
# 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
# 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
# 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
# File lib/backports/rails/hash.rb, line 8 8: def reverse_merge!(other_hash) 9: replace(reverse_merge(other_hash)) 10: end
# 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
# 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
# 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
# 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
# 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
# File lib/backports/rails/hash.rb, line 18 18: def symbolize_keys! 19: self.replace(self.symbolize_keys) 20: end