Class: Literal::Types::InterfaceType Private
- Inherits:
-
Object
- Object
- Literal::Types::InterfaceType
- Includes:
- Literal::Type
- Defined in:
- lib/literal/types/interface_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
- OwnClassTypeMethodOwners =
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.
List of ‘===` method owners where the comparison will only match for objects with the same class
Set[String, Integer, Kernel, Float, NilClass, TrueClass, FalseClass].freeze
Instance Attribute Summary collapse
- #methods ⇒ Object readonly private
Instance Method Summary collapse
- #===(value) ⇒ Object private
- #>=(other) ⇒ Object private
-
#initialize(*methods) ⇒ InterfaceType
constructor
private
A new instance of InterfaceType.
- #inspect ⇒ Object private
Constructor Details
#initialize(*methods) ⇒ InterfaceType
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 InterfaceType.
10 11 12 13 14 |
# File 'lib/literal/types/interface_type.rb', line 10 def initialize(*methods) raise Literal::ArgumentError.new("_Interface type must have at least one method.") if methods.size < 1 @methods = methods.to_set.freeze freeze end |
Instance Attribute Details
#methods ⇒ Object (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.
16 17 18 |
# File 'lib/literal/types/interface_type.rb', line 16 def methods @methods 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.
22 23 24 25 26 27 28 |
# File 'lib/literal/types/interface_type.rb', line 22 def ===(value) @methods.each do |method| return false unless value.respond_to?(method) end true 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.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/literal/types/interface_type.rb', line 30 def >=(other) case other when Literal::Types::InterfaceType @methods.subset?(other.methods) when Module public_methods = other.public_instance_methods.to_set @methods.subset?(public_methods) when Literal::Types::IntersectionType other.types.any? { |type| Literal.subtype?(type, self) } when Literal::Types::ConstraintType other.object_constraints.any? { |type| Literal.subtype?(type, self) } else if OwnClassTypeMethodOwners.include?(other.method(:===).owner) self === other else false end end end |
#inspect ⇒ 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.
18 19 20 |
# File 'lib/literal/types/interface_type.rb', line 18 def inspect "_Interface(#{@methods.map(&:inspect).join(', ')})" end |