Top Level Namespace

Defined Under Namespace

Modules: ParseTreeComm, Reg Classes: CachedResults, Class, Float, NeverExecThis, ParseTree, ParseTreeServer, ProblemFiles, Proc, RedParse, Ripper, RubyParser

Instance Method Summary collapse

Instance Method Details

#arraydiff(a, b) ⇒ Object



2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
# File 'lib/redparse.rb', line 2022

def arraydiff(a,b)
  a==b and return [a,false]
  (Array===a or a=[a])
  result= a.dup
  diff=false
  size= a.size >= b.size ? a.size : b.size
  size.times{|i|
    ai=a[i]
    bi=b[i]
    if Array===ai and Array===bi
      result_i,diff_i= arraydiff(ai,bi)
      diff||=diff_i
      result[i]=result_i
    elsif ai!=bi
      next if Regexp===ai and ai.to_s==bi.to_s and 
        ai.options==bi.options 
      diff=true
      result[i]={ai=>bi}
    elsif ai.nil? 
      result[i]={'size mismatch'=>"#{a.size} for #{b.size}"} if a.size!=b.size
      diff=true
    end
    if i.nonzero? and Hash===result[i] and Hash===result[i-1]
      old=result[i-1]
      oldkeys=old.keys
      oldvals=old.values
      if Reg::Subseq===oldkeys.first
        oldkeys=oldkeys.children
        oldval=oldvals.children
      end
      result[i-1..i]=[ {-[*oldkeys+result[i].keys]=>-[*oldvals+result[i].values]} ]
    end
  }
  return result,diff
end