Class: RBS::Subtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/subtractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(minuend, subtrahend) ⇒ Subtractor

Returns a new instance of Subtractor.



5
6
7
8
# File 'lib/rbs/subtractor.rb', line 5

def initialize(minuend, subtrahend)
  @minuend = minuend
  @subtrahend = subtrahend
end

Instance Method Details

#call(minuend = @minuend, context: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rbs/subtractor.rb', line 10

def call(minuend = @minuend, context: nil)
  minuend.map do |decl|
    case decl
    when AST::Declarations::Constant
      name = absolute_typename(decl.name, context: context)
      decl unless @subtrahend.constant_name?(name)
    when AST::Declarations::Interface
      name = absolute_typename(decl.name, context: context)
      decl unless @subtrahend.interface_name?(name)
    when AST::Declarations::Class, AST::Declarations::Module
      name = absolute_typename(decl.name, context: context)
      case
      when @subtrahend.class_decl?(name) && decl.is_a?(AST::Declarations::Class)
        filter_members(decl, context: context)
      when @subtrahend.module_decl?(name) && decl.is_a?(AST::Declarations::Module)
        filter_members(decl, context: context)
      when @subtrahend.constant_name?(name)
        nil
      else
        decl
      end
    when AST::Declarations::Global
      decl unless @subtrahend.global_decls[decl.name]
    when AST::Declarations::TypeAlias
      name = absolute_typename(decl.name, context: context)
      decl unless @subtrahend.type_alias_decls[name]
    when AST::Declarations::ClassAlias
      name = absolute_typename(decl.new_name, context: context)
      decl unless @subtrahend.class_alias?(name) || @subtrahend.class_decl?(name)
    when AST::Declarations::ModuleAlias
      name = absolute_typename(decl.new_name, context: context)
      decl unless @subtrahend.module_alias?(name) || @subtrahend.module_decl?(name)
    else
      raise "unknwon decl: #{(_ = decl).class}"
    end
  end.compact
end