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.



13
14
15
16
# File 'lib/hashira/duplication/variance.rb', line 13

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

Instance Method Details

#kindsObject



18
19
20
21
22
# File 'lib/hashira/duplication/variance.rb', line 18

def kinds
  return [:structure] if @canonical.types != @other.types

  differing.map { |node| category(node) }.uniq
end

#shape_only?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/hashira/duplication/variance.rb', line 24

def shape_only?
  return false unless @canonical.types == @other.types

  named.any? && named.all? { |left, right| left.name != right.name }
end