Class: Hashira::Duplication::Variance

Inherits:
Object
  • Object
show all
Defined in:
lib/hashira/duplication/variance.rb

Constant Summary collapse

LITERALS =
%i[integer_node float_node string_node symbol_node].freeze
VALUED =
%i[integer_node float_node].freeze
NAMED =
%i[call_node constant_read_node constant_path_node
local_variable_read_node local_variable_write_node
instance_variable_read_node instance_variable_write_node].freeze
CONSTANTS =
%i[constant_read_node constant_path_node].freeze

Instance Method Summary collapse

Constructor Details

#initialize(canonical, other) ⇒ Variance

Returns a new instance of Variance.



11
12
13
14
# File 'lib/hashira/duplication/variance.rb', line 11

def initialize(canonical, other)
  @canonical = canonical
  @other = other
end

Instance Method Details

#kindsObject



16
17
18
19
# File 'lib/hashira/duplication/variance.rb', line 16

def kinds
  return [:structure] if @canonical.types != @other.types
  differing.map { |node| category(node) }.uniq
end

#structural?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/hashira/duplication/variance.rb', line 21

def structural?
  return false unless @canonical.types == @other.types
  named.any? && named.all? { |left, right| left.name != right.name }
end