Class: Vernacular::Modifiers::TypedMethodReturns

Inherits:
ASTModifier
  • Object
show all
Defined in:
lib/vernacular/modifiers/typed_method_returns.rb

Overview

Extends Ruby syntax to allow typed method return declarations, as in:

def my_method(argument_a, argument_b) = return_type; end

Defined Under Namespace

Modules: TypedMethodReturnsRewriter

Instance Attribute Summary

Attributes inherited from ASTModifier

#builder_extensions, #parser_extensions, #rewriter_block

Instance Method Summary collapse

Methods inherited from ASTModifier

#build_rewriter, #components, #extend_builder, #extend_parser, #modify

Constructor Details

#initializeTypedMethodReturns

Returns a new instance of TypedMethodReturns.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/vernacular/modifiers/typed_method_returns.rb', line 6

def initialize
  super

  extend_parser(:f_arglist, 'f_arglist tEQL cpath', <<~PARSE)
    result = @builder.type_check_arglist(*val)
  PARSE

  extend_builder(:type_check_arglist) do |arglist, equal, cpath|
    arglist << n(:type_check_arglist, [equal, cpath], nil)
  end

  build_rewriter { include TypedMethodReturnsRewriter }
end