Class: Vernacular::Modifiers::TypedMethodArgs

Inherits:
ASTModifier
  • Object
show all
Defined in:
lib/vernacular/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 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

#initializeTypedMethodArgs

Returns a new instance of TypedMethodArgs.



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

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