Class: Steep::Interface::Builder::Config
- Defined in:
- lib/steep/interface/builder.rb
Instance Attribute Summary collapse
-
#class_type ⇒ Object
readonly
Returns the value of attribute class_type.
-
#instance_type ⇒ Object
readonly
Returns the value of attribute instance_type.
-
#self_type ⇒ Object
readonly
Returns the value of attribute self_type.
-
#variable_bounds ⇒ Object
readonly
Returns the value of attribute variable_bounds.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(self_type:, class_type: nil, instance_type: nil, variable_bounds:) ⇒ Config
constructor
A new instance of Config.
- #subst ⇒ Object
- #upper_bound(a) ⇒ Object
- #validate_class_type ⇒ Object
- #validate_fvs(name, type) ⇒ Object
- #validate_instance_type ⇒ Object
- #validate_self_type ⇒ Object
Constructor Details
#initialize(self_type:, class_type: nil, instance_type: nil, variable_bounds:) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 |
# File 'lib/steep/interface/builder.rb', line 7 def initialize(self_type:, class_type: nil, instance_type: nil, variable_bounds:) @self_type = self_type @class_type = class_type @instance_type = instance_type @variable_bounds = variable_bounds end |
Instance Attribute Details
#class_type ⇒ Object (readonly)
Returns the value of attribute class_type.
5 6 7 |
# File 'lib/steep/interface/builder.rb', line 5 def class_type @class_type end |
#instance_type ⇒ Object (readonly)
Returns the value of attribute instance_type.
5 6 7 |
# File 'lib/steep/interface/builder.rb', line 5 def instance_type @instance_type end |
#self_type ⇒ Object (readonly)
Returns the value of attribute self_type.
5 6 7 |
# File 'lib/steep/interface/builder.rb', line 5 def self_type @self_type end |
#variable_bounds ⇒ Object (readonly)
Returns the value of attribute variable_bounds.
5 6 7 |
# File 'lib/steep/interface/builder.rb', line 5 def variable_bounds @variable_bounds end |
Class Method Details
.empty ⇒ Object
14 15 16 |
# File 'lib/steep/interface/builder.rb', line 14 def self.empty new(self_type: nil, variable_bounds: {}) end |
Instance Method Details
#subst ⇒ Object
18 19 20 21 22 |
# File 'lib/steep/interface/builder.rb', line 18 def subst if self_type || class_type || instance_type Substitution.build([], [], self_type: self_type, module_type: class_type, instance_type: instance_type) end end |
#upper_bound(a) ⇒ Object
52 53 54 |
# File 'lib/steep/interface/builder.rb', line 52 def upper_bound(a) variable_bounds.fetch(a, nil) end |
#validate_class_type ⇒ Object
32 33 34 |
# File 'lib/steep/interface/builder.rb', line 32 def validate_class_type validate_fvs(:class_type, class_type) end |
#validate_fvs(name, type) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/steep/interface/builder.rb', line 36 def validate_fvs(name, type) if type fvs = type.free_variables if fvs.include?(AST::Types::Self.instance) raise "#{name} cannot include 'self' type: #{type}" end if fvs.include?(AST::Types::Instance.instance) Steep.logger.fatal { "#{name} cannot include 'instance' type: #{type}" } raise "#{name} cannot include 'instance' type: #{type}" end if fvs.include?(AST::Types::Class.instance) raise "#{name} cannot include 'class' type: #{type}" end end end |
#validate_instance_type ⇒ Object
28 29 30 |
# File 'lib/steep/interface/builder.rb', line 28 def validate_instance_type validate_fvs(:instance_type, instance_type) end |
#validate_self_type ⇒ Object
24 25 26 |
# File 'lib/steep/interface/builder.rb', line 24 def validate_self_type validate_fvs(:self_type, self_type) end |