Sha256: b21673ca888cf22db1164df331c4d84dafddbe5988e3b2ce26404a3b6c82d191

Contents?: true

Size: 1.09 KB

Versions: 11

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module RubyNext
  module Language
    module Rewriters
      class EndlessMethodCommand < EndlessMethod
        NAME = "endless-method-command"
        SYNTAX_PROBE = "obj = Object.new; def obj.foo = puts 'Hello'"
        MIN_SUPPORTED_VERSION = Gem::Version.new("3.1.0")

        def process_def(node)
          return node unless command?(node)

          super(node)
        end

        def process_defs(node)
          return node unless command?(node)

          super(node)
        end

        private

        def command?(node)
          buffer = ::Parser::Source::Buffer.new("(endless-method-rewriter)").tap do |buffer|
            buffer.source = node.loc.expression.source
          end

          parser30.parse(buffer)
          false
        rescue ::Parser::SyntaxError
          true
        end

        def parser30
          require "parser/ruby30" unless defined?(::Parser::Ruby30)

          ::Parser::Ruby30.new(Language::Builder.new).tap do |prs|
            prs.diagnostics.all_errors_are_fatal = true
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ruby-next-core-1.0.3 lib/ruby-next/language/rewriters/3.1/endless_method_command.rb
ruby-next-core-1.0.2 lib/ruby-next/language/rewriters/3.1/endless_method_command.rb
ruby-next-core-1.0.1 lib/ruby-next/language/rewriters/3.1/endless_method_command.rb
ruby-next-core-1.0.0 lib/ruby-next/language/rewriters/3.1/endless_method_command.rb
ruby-next-core-1.0.0.rc.1 lib/ruby-next/language/rewriters/3.1/endless_method_command.rb
ruby-next-core-0.15.3 lib/ruby-next/language/rewriters/3.1/endless_method_command.rb
ruby-next-core-0.15.2 lib/ruby-next/language/rewriters/3.1/endless_method_command.rb
ruby-next-core-0.15.1 lib/ruby-next/language/rewriters/3.1/endless_method_command.rb
ruby-next-core-0.15.0 lib/ruby-next/language/rewriters/3.1/endless_method_command.rb
ruby-next-core-0.14.1 lib/ruby-next/language/rewriters/3.1/endless_method_command.rb
ruby-next-core-0.14.0 lib/ruby-next/language/rewriters/3.1/endless_method_command.rb