Module: T::Helpers

Extended by:
Sig
Included in:
Generic, Props, Props::ClassMethods, Props::CustomType, Props::Plugin, Props::Private::ApplyDefault
Defined in:
lib/types/helpers.rb,
lib/sorbet-runtime.rb

Overview

Use as a mixin with extend (‘extend T::Helpers`). Docs at sorbet.org/docs/

Constant Summary collapse

Private =
T::Private

Instance Method Summary collapse

Methods included from Sig

sig

Instance Method Details

#abstract!Object

Class/Module Helpers ###



13
14
15
16
17
18
19
20
21
22
# File 'lib/types/helpers.rb', line 13

def abstract!
  if defined?(super)
    # This is to play nicely with Rails' AbstractController::Base,
    # which also defines an `abstract!` method.
    # https://api.rubyonrails.org/classes/AbstractController/Base.html#method-c-abstract-21
    super
  end

  Private::Abstract::Declare.declare_abstract(self, type: :abstract)
end

#final!Object



28
29
30
# File 'lib/types/helpers.rb', line 28

def final!
  Private::Final.declare(self)
end

#interface!Object



24
25
26
# File 'lib/types/helpers.rb', line 24

def interface!
  Private::Abstract::Declare.declare_abstract(self, type: :interface)
end

#mixes_in_class_methods(mod, *mods) ⇒ Object

Causes a mixin to also mix in class methods from the named module.

Nearly equivalent to

def self.included(other)
  other.extend(mod)
end

Except that it is statically analyzed by sorbet.



45
46
47
# File 'lib/types/helpers.rb', line 45

def mixes_in_class_methods(mod, *mods)
  Private::Mixins.declare_mixes_in_class_methods(self, [mod].concat(mods))
end

#requires_ancestor(&block) ⇒ Object

Specify an inclusion or inheritance requirement for ‘self`.

Example:

module MyHelper
  extend T::Helpers

  requires_ancestor { Kernel }
end

class MyClass < BasicObject # error: `MyClass` must include `Kernel` (required by `MyHelper`)
  include MyHelper
end

TODO: implement the checks in sorbet-runtime.



64
# File 'lib/types/helpers.rb', line 64

def requires_ancestor(&block); end

#sealed!Object



32
33
34
# File 'lib/types/helpers.rb', line 32

def sealed!
  Private::Sealed.declare(self, Kernel.caller(1..1)&.first&.split(':')&.first)
end