Class: Vernacular::AST::Modifiers::TypedMethodArgs

Inherits:
Vernacular::ASTModifier
  • Object
show all
Defined in:
lib/vernacular/ast/modifiers/typed_method_args.rb

Overview

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

def my_method(argument_a : Integer, argument_b : String); end

Defined Under Namespace

Modules: TypedMethodArgsRewriter

Instance Method Summary collapse

Constructor Details

#initializeTypedMethodArgs

Returns a new instance of TypedMethodArgs.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vernacular/ast/modifiers/typed_method_args.rb', line 9

def initialize
  super

  extend_parser(:f_arg, 'f_arg tCOLON cpath', <<~PARSE)
    result = @builder.type_check_arg(*val)
  PARSE

  extend_builder(:type_check_arg) do |args, colon, cpath|
    location = args[0].loc.with_operator(loc(colon))
                      .with_expression(join_exprs(args[0], cpath))
    [n(:type_check_arg, [args, cpath], location)]
  end

  build_rewriter { include TypedMethodArgsRewriter }
end