Class: PrySorbet::UnwrapCommand

Inherits:
Pry::ClassCommand
  • Object
show all
Defined in:
lib/pry-sorbet/commands/unwrap_command.rb

Instance Method Summary collapse

Instance Method Details

#processObject



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
# File 'lib/pry-sorbet/commands/unwrap_command.rb', line 16

def process
  return unless defined?(T::Private::Methods)

  # For each signature wrapper, call the lambda associated with the wrapper
  # to finalize the method wrapping
  sig_wrappers = T::Private::Methods.instance_variable_get(:@sig_wrappers) || {}
  sig_wrappers.values.each do |sig_wrapper|
    sig_wrapper.call
  rescue NameError
  end

  # Now that all methods are properly wrapped with optimized wrappers
  # we can replace them with the original methods
  signatures_by_method = T::Private::Methods.instance_variable_get(:@signatures_by_method) || {}
  signatures_by_method.values.each do |signature|
    T::Configuration.without_ruby_warnings do
      T::Private::DeclState.current.without_on_method_added do
        if signature.mode == T::Private::Methods::Modes.abstract
          signature.owner.send(:remove_method, signature.method_name)
        else
          signature.owner.send(:define_method, signature.method_name, signature.method)
        end
      end
    end
  end
end