Module: RubyBreaker::TypeComparer

Includes:
TypeDefs
Defined in:
lib/rubybreaker/type/type_comparer.rb

Overview

This module compares two RubyBreaker-defined types for the syntactic equivalence.

Class Method Summary collapse

Class Method Details

.compare(lhs, rhs) ⇒ Object

This equal method determines whether two types are syntactically equivalent. Note that this is NOT a type equivalent check.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/rubybreaker/type/type_comparer.rb', line 95

def self.compare(lhs,rhs)
  if lhs == rhs
    is_equal = true
  elsif lhs.class != rhs.class 
    is_equal = false
  elsif lhs.instance_of?(NominalType)
    is_equal = (lhs.mod == rhs.mod)
  elsif lhs.instance_of?(SelfType)
    is_equal = rhs.instance_of?(SelfType)
  elsif lhs.instance_of?(DuckType)
    is_equal = duck_compare(lhs,rhs)
  elsif lhs.instance_of?(FusionType)
    is_equal = self.compare(lhs.nom_type, rhs.nom_type)        
    if is_equal # do more testing
      is_equal = duck_compare(lhs,rhs)
    end
  elsif lhs.instance_of?(MethodType)
    is_equal = lhs.meth_name == rhs.meth_name
    if is_equal # then do more testing
      is_equal = self.proc_compare(lhs,rhs)
    end
  elsif lhs.instance_of?(BlockType)
    is_equal = self.proc_compare(lhs,rhs)
  elsif lhs.instance_of?(MethodListType)
    is_equal = self.meth_list_compare(lhs,rhs)
  elsif lhs.instance_of?(OrType)
    is_equal = self.or_compare(lhs,rhs)
  elsif lhs.instance_of?(VarLengthType)
    is_equal = rhs.instance_of?(VarLengthType) && 
               self.compare(lhs.type, rhs.type)
  elsif lhs.instance_of?(OptionalType)
    is_equal = rhs.instance_of?(OptionalType) &&
               self.compare(lhs.type, rhs.type)
  else
    is_equal = lhs.class == rhs.class
  end
  return is_equal
end