Class: RubyNext::Language::Rewriters::MethodReference

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

Constant Summary collapse

NAME =
"method-reference"
SYNTAX_PROBE =
"Language.:transform"
MIN_SUPPORTED_VERSION =
Gem::Version.new(RubyNext::NEXT_VERSION)

Instance Attribute Summary

Attributes inherited from Base

#locals

Instance Method Summary collapse

Methods inherited from Base

#initialize, #s, unsupported_syntax?, unsupported_version?

Constructor Details

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

Instance Method Details

#on_meth_ref(node) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby-next/language/rewriters/proposed/method_reference.rb', line 11

def on_meth_ref(node)
  context.track! self

  receiver, mid = *node.children

  replace(
    node.children.first.loc.expression.end.join(
      node.loc.expression.end
    ),
    ".method(:#{mid})"
  )

  node.updated(
    :send,
    [
      receiver,
      :method,
      s(:sym, mid)
    ]
  )
end