Class: Steep::AST::Types::Proc
- Inherits:
-
Object
- Object
- Steep::AST::Types::Proc
- Defined in:
- lib/steep/ast/types/proc.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#return_type ⇒ Object
readonly
Returns the value of attribute return_type.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #back_type ⇒ Object
- #closed? ⇒ Boolean
- #free_variables ⇒ Object
- #hash ⇒ Object
-
#initialize(params:, return_type:, location: nil) ⇒ Proc
constructor
A new instance of Proc.
- #level ⇒ Object
- #map_type(&block) ⇒ Object
- #one_arg? ⇒ Boolean
- #subst(s) ⇒ Object
- #to_s ⇒ Object
- #with_location(new_location) ⇒ Object
Constructor Details
#initialize(params:, return_type:, location: nil) ⇒ Proc
Returns a new instance of Proc.
9 10 11 12 13 |
# File 'lib/steep/ast/types/proc.rb', line 9 def initialize(params:, return_type:, location: nil) @location = location @params = params @return_type = return_type end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
5 6 7 |
# File 'lib/steep/ast/types/proc.rb', line 5 def location @location end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/steep/ast/types/proc.rb', line 6 def params @params end |
#return_type ⇒ Object (readonly)
Returns the value of attribute return_type.
7 8 9 |
# File 'lib/steep/ast/types/proc.rb', line 7 def return_type @return_type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
15 16 17 18 19 |
# File 'lib/steep/ast/types/proc.rb', line 15 def ==(other) other.is_a?(self.class) && other.params == params && other.return_type == return_type end |
#back_type ⇒ Object
73 74 75 76 77 |
# File 'lib/steep/ast/types/proc.rb', line 73 def back_type Name::Instance.new(name: Builtin::Proc.module_name, args: [], location: location) end |
#closed? ⇒ Boolean
48 49 50 |
# File 'lib/steep/ast/types/proc.rb', line 48 def closed? params.closed? && return_type.closed? end |
#free_variables ⇒ Object
39 40 41 |
# File 'lib/steep/ast/types/proc.rb', line 39 def free_variables params.free_variables + return_type.free_variables end |
#hash ⇒ Object
21 22 23 |
# File 'lib/steep/ast/types/proc.rb', line 21 def hash self.class.hash && params.hash && return_type.hash end |
#level ⇒ Object
43 44 45 46 |
# File 'lib/steep/ast/types/proc.rb', line 43 def level children = params.each_type.to_a + [return_type] [0] + level_of_children(children) end |
#map_type(&block) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/steep/ast/types/proc.rb', line 56 def map_type(&block) self.class.new( params: params.map_type(&block), return_type: yield(return_type), location: location ) end |
#one_arg? ⇒ Boolean
64 65 66 67 68 69 70 71 |
# File 'lib/steep/ast/types/proc.rb', line 64 def one_arg? params.required.size == 1 && params.optional.empty? && !params.rest && params.required_keywords.empty? && params.optional_keywords.empty? && !params.rest_keywords end |
#subst(s) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/steep/ast/types/proc.rb', line 27 def subst(s) self.class.new( params: params.subst(s), return_type: return_type.subst(s), location: location ) end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/steep/ast/types/proc.rb', line 35 def to_s "^#{params} -> #{return_type}" end |
#with_location(new_location) ⇒ Object
52 53 54 |
# File 'lib/steep/ast/types/proc.rb', line 52 def with_location(new_location) self.class.new(location: new_location, params: params, return_type: return_type) end |