Sha256: b44c020a7ef1e9daf1bc91bb0d18dbe0b6edc7b9bc4b550eab8598dad2efb534

Contents?: true

Size: 1.04 KB

Versions: 11

Compression:

Stored size: 1.04 KB

Contents

#
# Copyright (C) 2013-2015 Globo.com
#

# This file is part of TDI.

# TDI is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# TDI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with TDI.  If not, see <http://www.gnu.org/licenses/>.

module HashRecursiveMerge
  def rmerge(other_hash)
    r = {}

    merge(other_hash) do |key, oldval, newval|
      r[key] = oldval.is_a?(Hash) ? oldval.rmerge(newval) : newval
    end
  end

  def rmerge!(other_hash)
    merge!(other_hash) do |key, oldval, newval|
      oldval.is_a?(Hash) ? oldval.rmerge!(newval) : newval
    end
  end
end

class Hash
  include HashRecursiveMerge
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
tdi-0.2.3 lib/rmerge.rb
tdi-0.2.2 lib/rmerge.rb
tdi-0.2.1 lib/rmerge.rb
tdi-0.2.0 lib/rmerge.rb
tdi-0.1.13 lib/rmerge.rb
tdi-0.1.12 lib/rmerge.rb
tdi-0.1.11 lib/rmerge.rb
tdi-0.1.10 lib/rmerge.rb
tdi-0.1.9 lib/rmerge.rb
tdi-0.1.8 lib/rmerge.rb
tdi-0.1.7 lib/rmerge.rb