Sha256: c779d6f14181e680445272c71be8c2413fd6b36bd7f200cf0ac7faf4fc20d813

Contents?: true

Size: 803 Bytes

Versions: 15

Compression:

Stored size: 803 Bytes

Contents

class ProcSourceParams < Array

  # 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
  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

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
procemon-0.6.3 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.6.2 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.6.1 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.5.0 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.4.5 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.4.4 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.4.3 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.4.2 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.4.1 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.4.0 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.3.4 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.3.3 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.3.2 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.3.1 lib/procemon/function/proc_source/proc_source_params.rb
procemon-0.2.0 lib/procemon/function/proc_source/proc_source_params.rb