Sha256: 0b0b882d594cd8755bb22b2adf9346e577adf46a98edf711e58cda9d4307d0d2

Contents?: true

Size: 1.05 KB

Versions: 19

Compression:

Stored size: 1.05 KB

Contents

# 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.

class AdvancedHash < Hash

    def deep_merge(second)
        merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
        self.merge(second, &merger)
    end

    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
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
avst-wizard-0.0.43 lib/advanced_hash.rb
avst-wizard-0.0.42 lib/advanced_hash.rb
avst-wizard-0.0.41 lib/advanced_hash.rb
avst-wizard-0.0.40 lib/advanced_hash.rb
avst-wizard-0.0.39 lib/advanced_hash.rb
avst-wizard-0.0.38 lib/advanced_hash.rb
avst-wizard-0.0.37 lib/advanced_hash.rb
avst-wizard-0.0.36 lib/advanced_hash.rb
avst-wizard-0.0.35 lib/advanced_hash.rb
avst-wizard-0.0.34 lib/advanced_hash.rb
avst-wizard-0.0.31 lib/advanced_hash.rb
avst-wizard-0.0.30 lib/advanced_hash.rb
avst-wizard-0.0.28 lib/advanced_hash.rb
avst-wizard-0.0.27 lib/advanced_hash.rb
avst-wizard-0.0.26 lib/advanced_hash.rb
avst-wizard-0.0.25 lib/advanced_hash.rb
avst-wizard-0.0.24 lib/advanced_hash.rb
avst-wizard-0.0.23 lib/advanced_hash.rb
avst-wizard-0.0.22 lib/advanced_hash.rb