class Hash

Public Instance Methods

+(other) click to toggle source
# File lib/rubyhacks.rb, line 408
def +(other)
        temp = {}
        raise TypeError unless other.class == Hash
        self.each do |key, value|
                raise "Non unique key set for Hash + Hash" unless other[key].class == NilClass
                temp[key] = value
        end
        other.each do |key, value|
                raise "Non unique key set for Hash + Hash" unless self[key].class == NilClass
                temp[key] = value
        end
        return temp
end
absorb(hash, excludes=[])
Alias for: modify
expand_bools() click to toggle source
# File lib/rubyhacks.rb, line 448
def expand_bools
        self[:true].each do |key|
                self[key] = true
        end
        self[:false].each do |key|
                self[key] = false
        end
        self
end
modify(hash, excludes=[]) click to toggle source
# File lib/rubyhacks.rb, line 435
        def modify(hash, excludes=[])
                hash.each do |key, value|
#                       p key
                        begin
                                self[key] = value.dup unless excludes.include? key
                        rescue TypeError #immediate values cannot be dup'd
                                self[key] = value unless excludes.include? key
                        end
                end
                self
        end
Also aliased as: absorb
random() click to toggle source
# File lib/rubyhacks.rb, line 431
def random
        key = random_key
        return {key =>  self[key]}
end
random_key() click to toggle source
# File lib/rubyhacks.rb, line 427
def random_key
        keys.random
end
random_value() click to toggle source
# File lib/rubyhacks.rb, line 423
def random_value
        self[random_key]
end