Sha256: 8d671fe17b7cf9d23db1b76bbe4c6fd3ab693bf2d21a9cf49b0d23cdff1eb176

Contents?: true

Size: 915 Bytes

Versions: 40

Compression:

Stored size: 915 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 Order
    def order_by(ary)
      ary << "..." if not ary.include? "..."
      order_ary = ary.inject([[]]) do |a, x|
        x != "..." ? a.last << x : a<< []; a
      end
      order_by_direction(order_ary.first, :before)
      order_by_direction(order_ary.last, :after)
      self
    end

  private
    def order_by_direction(ary, direction)
      ary = ary.reverse if direction == :before
      ary.each do |f|
        next unless i = self.index {|x| x =~ /#{f}/i}
        item = self.delete_at i
        direction == :before ? self.unshift(item) : self.push(item)
      end
    end
  end
end

class Hash
  include Linner::HashRecursiveMerge
end

class Array
  include Linner::Order
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
linner-0.7.3 lib/linner/helper.rb
linner-0.7.2 lib/linner/helper.rb
linner-0.7.1 lib/linner/helper.rb
linner-0.7.0 lib/linner/helper.rb
linner-0.6.7 lib/linner/helper.rb
linner-0.6.6 lib/linner/helper.rb
linner-0.6.5 lib/linner/helper.rb
linner-0.6.4 lib/linner/helper.rb
linner-0.6.3 lib/linner/helper.rb
linner-0.6.2 lib/linner/helper.rb
linner-0.6.1 lib/linner/helper.rb
linner-0.6.0 lib/linner/helper.rb
linner-0.5.1 lib/linner/helper.rb
linner-0.5.0 lib/linner/helper.rb
linner-0.4.6 lib/linner/helper.rb
linner-0.4.5 lib/linner/helper.rb
linner-0.4.4 lib/linner/helper.rb
linner-0.4.3 lib/linner/helper.rb
linner-0.4.2 lib/linner/helper.rb
linner-0.4.1 lib/linner/helper.rb