Class: AdvancedHash
- Inherits:
-
Hash
- Object
- Hash
- AdvancedHash
- Defined in:
- lib/advanced_hash.rb
Overview
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.
Instance Method Summary collapse
Instance Method Details
#[](a) ⇒ Object
22 23 24 25 26 27 28 29 |
# 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) ⇒ Object
17 18 19 20 |
# 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 |