Class: Yoda::Typing::Types::Function
- Defined in:
- lib/yoda/typing/types/function.rb
Instance Attribute Summary collapse
- #block_parameter ⇒ (String, Base)? readonly
- #context ⇒ Base? readonly
- #keyword_parameters ⇒ Array<(String, Base)> readonly
- #keyword_rest_parameter ⇒ Base readonly
- #parameters ⇒ Array<Base> readonly
- #post_parameters ⇒ Array<Base> readonly
- #rest_parameter ⇒ Array<Base> readonly
- #return_type ⇒ Base readonly
Instance Method Summary collapse
-
#initialize(context: nil, return_type:, parameters: [], rest_parameter: nil, post_parameters: [], keyword_parameters: [], keyword_rest_parameter: nil, block_parameter: nil) ⇒ Function
constructor
A new instance of Function.
- #to_expression ⇒ Object
- #to_type_string ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(context: nil, return_type:, parameters: [], rest_parameter: nil, post_parameters: [], keyword_parameters: [], keyword_rest_parameter: nil, block_parameter: nil) ⇒ Function
Returns a new instance of Function.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/yoda/typing/types/function.rb', line 37 def initialize(context: nil, return_type:, parameters: [], rest_parameter: nil, post_parameters: [], keyword_parameters: [], keyword_rest_parameter: nil, block_parameter: nil) @context = context @parameters = parameters @keyword_parameters = keyword_parameters @rest_parameter = rest_parameter @post_parameters = post_parameters @keyword_rest_parameter = keyword_rest_parameter @block_parameter = block_parameter @return_type = return_type end |
Instance Attribute Details
#block_parameter ⇒ (String, Base)? (readonly)
24 25 26 |
# File 'lib/yoda/typing/types/function.rb', line 24 def block_parameter @block_parameter end |
#context ⇒ Base? (readonly)
6 7 8 |
# File 'lib/yoda/typing/types/function.rb', line 6 def context @context end |
#keyword_parameters ⇒ Array<(String, Base)> (readonly)
18 19 20 |
# File 'lib/yoda/typing/types/function.rb', line 18 def keyword_parameters @keyword_parameters end |
#keyword_rest_parameter ⇒ Base (readonly)
21 22 23 |
# File 'lib/yoda/typing/types/function.rb', line 21 def keyword_rest_parameter @keyword_rest_parameter end |
#parameters ⇒ Array<Base> (readonly)
9 10 11 |
# File 'lib/yoda/typing/types/function.rb', line 9 def parameters @parameters end |
#post_parameters ⇒ Array<Base> (readonly)
15 16 17 |
# File 'lib/yoda/typing/types/function.rb', line 15 def post_parameters @post_parameters end |
#rest_parameter ⇒ Array<Base> (readonly)
12 13 14 |
# File 'lib/yoda/typing/types/function.rb', line 12 def rest_parameter @rest_parameter end |
#return_type ⇒ Base (readonly)
27 28 29 |
# File 'lib/yoda/typing/types/function.rb', line 27 def return_type @return_type end |
Instance Method Details
#to_expression ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/yoda/typing/types/function.rb', line 48 def to_expression Model::TypeExpressions::FunctionType.new( context: context&.to_expression, return_type: return_type.to_expression, parameters: parameters.map(&:to_expression), rest_parameter: rest_parameter&.to_expression, post_parameters: post_parameters.map(&:to_expression), keyword_parameters: keyword_parameters.map { |keyword, type| [keyword, type.to_expression] }, keyword_rest_parameter: keyword_rest_parameter&.to_expression, block_parameter: block_parameter&.to_expression, ) end |
#to_type_string ⇒ Object
61 62 63 64 |
# File 'lib/yoda/typing/types/function.rb', line 61 def to_type_string inspect # "#{context.to_type_string}()" end |