Class: Yoda::Model::TypeExpressions::FunctionType::Parameter
- Inherits:
- 
      Object
      
        - Object
- Yoda::Model::TypeExpressions::FunctionType::Parameter
 
- Defined in:
- lib/yoda/model/type_expressions/function_type/parameter.rb
Instance Attribute Summary collapse
- #name ⇒ String? readonly
- #type ⇒ Base readonly
Instance Method Summary collapse
- #==(another) ⇒ Object
- #block_expression ⇒ String
- #eql?(another) ⇒ Boolean
- #hash ⇒ Object
- 
  
    
      #initialize(name: nil, type:)  ⇒ Parameter 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Parameter. 
- #keyword_expression(optional: false) ⇒ String
- #keyword_rest_expression ⇒ String
- #map_type(&block) ⇒ Object
- #optional_expression ⇒ String
- #optional_keyword_expression ⇒ String
- #positional_expression(optioanl: false, rest: false, block: false) ⇒ String
- #rest_expression ⇒ String
- #to_rbs_param(env) ⇒ RBS::Types::Function::Param
Constructor Details
#initialize(name: nil, type:) ⇒ Parameter
Returns a new instance of Parameter.
| 14 15 16 17 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 14 def initialize(name: nil, type:) @name = name @type = type end | 
Instance Attribute Details
#name ⇒ String? (readonly)
| 7 8 9 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 7 def name @name end | 
#type ⇒ Base (readonly)
| 10 11 12 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 10 def type @type end | 
Instance Method Details
#==(another) ⇒ Object
| 29 30 31 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 29 def ==(another) eql?(another) end | 
#block_expression ⇒ String
| 68 69 70 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 68 def block_expression positional_expression(block: true) end | 
#eql?(another) ⇒ Boolean
| 33 34 35 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 33 def eql?(another) another.is_a?(Parameter) && name == another.name && type == another.type end | 
#hash ⇒ Object
| 37 38 39 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 37 def hash [self.class.name, name, type].hash end | 
#keyword_expression(optional: false) ⇒ String
| 42 43 44 45 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 42 def keyword_expression(optional: false) prefix = optional ? "?" : "" "#{prefix}#{name}: #{type}" end | 
#keyword_rest_expression ⇒ String
| 53 54 55 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 53 def keyword_rest_expression "**#{type} #{name}" end | 
#map_type(&block) ⇒ Object
| 25 26 27 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 25 def map_type(&block) self.class.new(name: name, type: block.call(type)) end | 
#optional_expression ⇒ String
| 58 59 60 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 58 def optional_expression positional_expression(optional: true) end | 
#optional_keyword_expression ⇒ String
| 48 49 50 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 48 def optional_keyword_expression keyword_expression(optional: true) end | 
#positional_expression(optioanl: false, rest: false, block: false) ⇒ String
| 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 73 def positional_expression(optioanl: false, rest: false, block: false) prefix = begin if optional "?" elsif rest "*" elsif block "&" else "" end end if name "#{prefix}#{type} #{name}" else "#{prefix}#{type}" end end | 
#rest_expression ⇒ String
| 63 64 65 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 63 def rest_expression positional_expression(rest: true) end | 
#to_rbs_param(env) ⇒ RBS::Types::Function::Param
| 21 22 23 | # File 'lib/yoda/model/type_expressions/function_type/parameter.rb', line 21 def to_rbs_param(env) RBS::Types::Function::Param.new(type: type.to_rbs_type(env), name: name.to_sym) end |