Class: Sourcerer::ProcSourceParams

Inherits:
Array
  • Object
show all
Defined in:
lib/sourcerer/proc_source_params.rb

Instance Method Summary collapse

Instance Method Details

#+(oth_ary) ⇒ Object

merge two proc params obj if multiple rest obj found it will remove and make an *args obj as last element if they are not equal , else it makes it the last element only



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sourcerer/proc_source_params.rb', line 9

def +(oth_ary)

  merged_array= (Array[*self]+Array[*oth_ary])

  rest_state= nil
  rest_elements= Array.new
  merged_array.dup.each do |element|
    if element.include? '*'
      merged_array.delete(element)
      rest_state ||= true
      rest_elements.push(element)
    end
  end

  rest_elements.uniq!
  if rest_elements.count == 1 && !rest_elements.empty?
    merged_array.push(rest_elements[0])
    rest_state= nil
  end

  unless rest_state.nil?
    merged_array.push('*args')
  end

  return ProcSourceParams[*merged_array]
end