class AdvancedHash

Copyright 2015 Adaptavist.com Ltd.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Public Instance Methods

[](a) click to toggle source
# File lib/advanced_hash.rb, line 22
def [](a)
    r = Regexp.new a.to_s
    found = self.select {|k| k =~ r}
    if found.keys.count > 1
        raise "Found multiple values that matches the stage, make sure they are unique. For #{a.to_s} found #{found.keys.inspect} "
    end
    found.values[0]
end
deep_merge(second) click to toggle source
# File lib/advanced_hash.rb, line 17
def deep_merge(second)
    merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
    self.merge(second, &merger)
end