Sha256: d05ec9ff6cb3760aaf3e27c45a4dd1a1cbe38fc858a34ade40ef643eda4b5bcd

Contents?: true

Size: 844 Bytes

Versions: 5

Compression:

Stored size: 844 Bytes

Contents

module Linner
  module HashRecursiveMerge
    def rmerge!(other_hash)
      merge!(other_hash) do |key, oldval, newval|
        oldval.class == self.class ? oldval.rmerge!(newval) : newval
      end
    end
  end

  module Sort
    def sort_by_before_and_after(before, after)
      sort_by_before(self, before)
      sort_by_after(self, after)
      self
    end

    private
    def sort_by_before(list, before)
      before.reverse.each do |f|
        if i = list.index {|x| x =~ /#{f}/i}
          list.unshift list.delete_at i
        end
      end
    end

    def sort_by_after(list, after)
      after.reverse.each do |f|
        if i = list.index {|x| x =~ /#{f}/i}
          list.push list.delete_at i
        end
      end
    end
  end
end

class Hash
  include Linner::HashRecursiveMerge
end

class Array
  include Linner::Sort
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
linner-0.1.5 lib/linner/helper.rb
linner-0.1.4 lib/linner/helper.rb
linner-0.1.3 lib/linner/helper.rb
linner-0.1.2 lib/linner/helper.rb
linner-0.1.1 lib/linner/helper.rb