Module: Rtype::MethodAnnotator::ClassMethods

Defined in:
lib/rtype/method_annotator.rb

Instance Method Summary collapse

Instance Method Details

#method_added(name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rtype/method_annotator.rb', line 8

def method_added(name)
  if @_rtype_component
    compo = @_rtype_component
    
    if compo.annotation_mode && !compo.ignoring
      if compo.has_undef?(name, false)
        compo.remove_undef(name, false)
      end
      
      compo.ignoring = true
      ::Rtype::define_typed_method(self, name, compo.annotation_type_sig, false)
      compo.annotation_mode = false
      compo.annotation_type_sig = nil
      compo.ignoring = false
      
    elsif compo.has_undef?(name, false)
      info = compo.get_undef(name, false)
      compo.remove_undef(name, false)
      ::Rtype.send(:redefine_method_to_typed, self, name, info[:expected], info[:result], false)
    end
  end
end

#singleton_method_added(name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rtype/method_annotator.rb', line 31

def singleton_method_added(name)
  if @_rtype_component
    compo = @_rtype_component
    
    if compo.annotation_mode && !compo.ignoring
      if compo.has_undef?(name, true)
        compo.remove_undef(name, true)
      end
      
      compo.ignoring = true
      ::Rtype::define_typed_method(self, name, compo.annotation_type_sig, true)
      compo.annotation_mode = false
      compo.annotation_type_sig = nil
      compo.ignoring = false
      
    elsif compo.has_undef?(name, true)
      info = compo.get_undef(name, true)
      compo.remove_undef(name, true)
      ::Rtype.send(:redefine_method_to_typed, self, name, info[:expected], info[:result], true)
    end
  end
end