Class: Rigor::Environment::RbsHierarchy

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/environment/rbs_hierarchy.rb,
sig/rigor/environment.rbs

Overview

Small hierarchy oracle backed by RBS instance definitions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loader) ⇒ RbsHierarchy

Returns a new instance of RbsHierarchy.

Parameters:



7
8
9
10
11
# File 'lib/rigor/environment/rbs_hierarchy.rb', line 7

def initialize(loader)
  @loader = loader
  @ancestor_names_cache = {}
  @class_ordering_cache = {}
end

Instance Attribute Details

#loaderRbsLoader (readonly)

Returns the value of attribute loader.

Returns:



26
27
28
# File 'lib/rigor/environment/rbs_hierarchy.rb', line 26

def loader
  @loader
end

Instance Method Details

#class_ordering(lhs, rhs) ⇒ ordering

Parameters:

  • lhs (String, Symbol)
  • rhs (String, Symbol)

Returns:

  • (ordering)


13
14
15
16
17
18
19
20
21
22
# File 'lib/rigor/environment/rbs_hierarchy.rb', line 13

def class_ordering(lhs, rhs)
  lhs = normalize_name(lhs)
  rhs = normalize_name(rhs)
  return :equal if lhs == rhs

  key = [lhs, rhs]
  return @class_ordering_cache[key] if @class_ordering_cache.key?(key)

  @class_ordering_cache[key] = compute_class_ordering(lhs, rhs)
end

#normalize_name(name) ⇒ String

Parameters:

  • name (String, Symbol)

Returns:

  • (String)


72
73
74
# File 'lib/rigor/environment/rbs_hierarchy.rb', line 72

def normalize_name(name)
  name.to_s.delete_prefix("::")
end