Sha256: 679c7879c867bf9f3d3c065c9fdbfc03bf9c8b35108f2d82366df43804c0861b
Contents?: true
Size: 1.45 KB
Versions: 130
Compression:
Stored size: 1.45 KB
Contents
# frozen_string_literal: true # typed: true class T::InexactStruct include T::Props include T::Props::Serializable include T::Props::Constructor end class T::Struct < T::InexactStruct def self.inherited(subclass) super(subclass) T::Private::ClassUtils.replace_method(subclass.singleton_class, :inherited, true) do |s| super(s) raise "#{self.name} is a subclass of T::Struct and cannot be subclassed" end end end class T::ImmutableStruct < T::InexactStruct extend T::Sig def self.inherited(subclass) super(subclass) T::Private::ClassUtils.replace_method(subclass.singleton_class, :inherited, true) do |s| super(s) raise "#{self.name} is a subclass of T::ImmutableStruct and cannot be subclassed" end end # Matches the one in WeakConstructor, but freezes the object sig {params(hash: T::Hash[Symbol, T.untyped]).void.checked(:never)} def initialize(hash={}) super freeze end # Matches the signature in Props, but raises since this is an immutable struct and only const is allowed sig {params(name: Symbol, cls: T.untyped, rules: T.untyped).void} def self.prop(name, cls, **rules) return super if (cls.is_a?(Hash) && cls[:immutable]) || rules[:immutable] raise "Cannot use `prop` in #{self.name} because it is an immutable struct. Use `const` instead" end def with(changed_props) raise "Cannot use `with` in #{self.class.name} because it is an immutable struct" end end
Version data entries
130 entries across 130 versions & 1 rubygems