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-hc-1.0.0 lib/linner/helper.rb
linner-0.12.0 lib/linner/helper.rb
linner-0.11.6 lib/linner/helper.rb
linner-0.11.5 lib/linner/helper.rb
linner-0.11.4 lib/linner/helper.rb
linner-0.11.3 lib/linner/helper.rb
linner-0.11.2 lib/linner/helper.rb
linner-0.11.1 lib/linner/helper.rb
linner-0.11.0 lib/linner/helper.rb
linner-0.10.0 lib/linner/helper.rb
linner-0.9.1 lib/linner/helper.rb
linner-0.9.0 lib/linner/helper.rb
linner-0.8.7 lib/linner/helper.rb
linner-0.8.6 lib/linner/helper.rb
linner-0.8.5 lib/linner/helper.rb
linner-0.8.4 lib/linner/helper.rb
linner-0.8.3 lib/linner/helper.rb
linner-0.8.2 lib/linner/helper.rb
linner-0.8.1 lib/linner/helper.rb
linner-0.8.0 lib/linner/helper.rb