Module: TypeAssertImpl

Included in:
TA
Defined in:
lib/sorbet-rails/type_assert/type_assert.rb,
lib/sorbet-rails/type_assert/type_assert_impl.rb

Overview

Make this type visible even when the concrete implementation cannot be loaded.

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sorbet-rails/type_assert/type_assert_impl.rb', line 6

def self.included(klass)
  klass.define_singleton_method(:[]) do |type|
    return Class.new do
      include ITypeAssert

      define_method(:to_s) { "TA[#{type.to_s}]" }

      define_method(:assert) do |val|
        T.let(val, type)
      end

      define_method(:get_type) { type }
    end
  end
end