lib/vidibus/core_extensions/array.rb
# Merges given array with current one.
#
# Will perform insertion of new items by three rules:
# 1. If the item's predecessor is present, insert item after it.
# 2. If the item's follower is present, insert item before it.
# 3. Insert item at end of list.
#
# Examples:
#
#   [].merge([1, 2])            # => [1, 2]
#   ['a'].merge([1, 2])         # => ['a', 1, 2]
#   [1, 'a'].merge([1, 2])      # => [1, 2, 'a']
#   [1, 'a'].merge([3, 1, 2])   # => [3, 1, 2, 'a']
#
Merges given array with current one.
Will perform insertion of new items by three rules:
1. If the item's predecessor is present, insert item after it.
2. If the item's follower is present, insert item before it.
3. Insert item at end of list.




Merges given array with current one . Will perform insertion of new items by three rules : 1 . If the item ' s predecessor is present insert item after it . 2 . If the item ' s follower is present insert item before it . 3 . Insert item at end of list .
def merge(array, options = {})
    strict = options[:strict]
    exclude = options[:exclude] || []
    list = array.dup
    for value in list
      array.delete(value) and next if include?(value) or exclude.include?(value)
      position = nil
      if found = merging_predecessor(value, list)
        position = index(found) + 1
      elsif found = merging_follower(value, list)
        position = index(found)
      end
      if position or !strict
        insert(position || length, value)
        array.delete(value)
      end
    end
    self
  end
def merge ( array , options = { } ) strict = options [ :strict ] exclude = options [ :exclude ] || [ ] list = array . dup for value in list array . delete ( value ) and next if include? ( value ) or exclude . include? ( value ) position = nil if found = merging_predecessor ( value , list ) position = index ( found ) + 1 elsif found = merging_follower ( value , list ) position = index ( found ) end if position or ! strict insert ( position || length , value ) array . delete ( value ) end end self end
Merges given array with current one.
Merges given array with current one .
array
<not_specific>
options
<not_specific>