Class: RubyNext::Language::Rewriters::RequiredKwargs

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby-next/language/rewriters/2.1/required_kwargs.rb

Constant Summary collapse

NAME =
"required-kwargs"
SYNTAX_PROBE =
"obj = Object.new; def obj.foo(x:, y: 1); end"
MIN_SUPPORTED_VERSION =
Gem::Version.new("2.1.0")

Instance Attribute Summary

Attributes inherited from Base

#locals

Instance Method Summary collapse

Methods inherited from Base

ast?, #initialize, #s

Methods inherited from Abstract

ast?, #initialize, text?, transform, unsupported_syntax?, unsupported_version?

Constructor Details

This class inherits a constructor from RubyNext::Language::Rewriters::Base

Instance Method Details

#on_kwarg(node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby-next/language/rewriters/2.1/required_kwargs.rb', line 13

def on_kwarg(node)
  context.track! self

  name = node.children[0]

  new_node = node.updated(
    :kwoptarg,
    [name, raise_missing_keyword(name)]
  )

  replace(node.loc.expression, "#{name}: ::Kernel.raise(::ArgumentError, \"missing keyword: #{name}\")")

  new_node
end