Class: T::ImmutableStruct
- Inherits:
-
InexactStruct
- Object
- InexactStruct
- T::ImmutableStruct
- Defined in:
- lib/sorbet/eraser/t/struct.rb
Class Method Summary collapse
- .inherited(child) ⇒ Object
-
.prop(name, rules = {}) ⇒ Object
Matches the signature in Props, but raises since this is an immutable struct and only const is allowed.
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ ImmutableStruct
constructor
A new instance of ImmutableStruct.
- #with(changed_props) ⇒ Object
Methods included from Props
Constructor Details
#initialize(hash = {}) ⇒ ImmutableStruct
Returns a new instance of ImmutableStruct.
36 37 38 39 |
# File 'lib/sorbet/eraser/t/struct.rb', line 36 def initialize(hash = {}) super freeze end |
Class Method Details
.inherited(child) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/sorbet/eraser/t/struct.rb', line 27 def self.inherited(child) super(child) child.define_singleton_method(:inherited) do |grandchild| super(grandchild) raise "#{grandchild.name} is a subclass of T::ImmutableStruct and cannot be subclassed" end end |
.prop(name, rules = {}) ⇒ Object
Matches the signature in Props, but raises since this is an immutable struct and only const is allowed
42 43 44 45 46 |
# File 'lib/sorbet/eraser/t/struct.rb', line 42 def self.prop(name, rules = {}) return super if rules[:immutable] raise "Cannot use `prop` in #{self.name} because it is an immutable struct. Use `const` instead" end |
Instance Method Details
#with(changed_props) ⇒ Object
48 49 50 |
# File 'lib/sorbet/eraser/t/struct.rb', line 48 def with(changed_props) raise "Cannot use `with` in #{self.class.name} because it is an immutable struct" end |