Sha256: e4d1dd903918c6bcfe1c958a9d05e1a180b46d0a4a74c5ecb47d544a77aaf672

Contents?: true

Size: 880 Bytes

Versions: 3

Compression:

Stored size: 880 Bytes

Contents

module Sourcerer
  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
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sourcerer-0.5.2 lib/sourcerer/proc_source_params.rb
sourcerer-0.5.1 lib/sourcerer/proc_source_params.rb
sourcerer-0.5.0.pre.beta lib/sourcerer/proc_source_params.rb