Class: Literal::Types::FrozenType Private

Inherits:
Object
  • Object
show all
Includes:
Literal::Type
Defined in:
lib/literal/types/frozen_type.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

ALWAYS_FROZEN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Set[Symbol, Integer, Float, Numeric, true, false, nil].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ FrozenType

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FrozenType.



9
10
11
12
13
14
15
16
# File 'lib/literal/types/frozen_type.rb', line 9

def initialize(type)
	if ALWAYS_FROZEN.include?(type)
		warn "_Frozen type is redundant for #{type.inspect} since it is always frozen."
	end

	@type = type
	freeze
end

Instance Attribute Details

#typeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
# File 'lib/literal/types/frozen_type.rb', line 18

def type
  @type
end

Instance Method Details

#===(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def ===(value)
	value.frozen? && @type === value
end

#>=(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/literal/types/frozen_type.rb', line 28

def >=(other)
	case other
	when Literal::Types::FrozenType
		@type >= other.type
	when Literal::Types::ConstraintType
		type_match = false
		frozen_match = Literal.subtype?(other.property_constraints[:frozen?], true)

		other.object_constraints.each do |constraint|
			frozen_match ||= ALWAYS_FROZEN.include?(constraint)
			type_match ||= Literal.subtype?(constraint, @type)
			return true if frozen_match && type_match
		end

		false
	else
		false
	end
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/literal/types/frozen_type.rb', line 20

def inspect
	"_Frozen(#{@type.inspect})"
end