Sha256: 3177f9c24f4a01d2e5b0cb8c5ff43f636c83e44ef739dfb3a27b5582953d2f25

Contents?: true

Size: 1.57 KB

Versions: 17

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module IRB
  class Statement
    attr_reader :code

    def is_assignment?
      raise NotImplementedError
    end

    def suppresses_echo?
      raise NotImplementedError
    end

    def should_be_handled_by_debugger?
      raise NotImplementedError
    end

    def evaluable_code
      raise NotImplementedError
    end

    class Expression < Statement
      def initialize(code, is_assignment)
        @code = code
        @is_assignment = is_assignment
      end

      def suppresses_echo?
        @code.match?(/;\s*\z/)
      end

      def should_be_handled_by_debugger?
        true
      end

      def is_assignment?
        @is_assignment
      end

      def evaluable_code
        @code
      end
    end

    class Command < Statement
      def initialize(code, command, arg, command_class)
        @code = code
        @command = command
        @arg = arg
        @command_class = command_class
      end

      def is_assignment?
        false
      end

      def suppresses_echo?
        false
      end

      def should_be_handled_by_debugger?
        require_relative 'cmd/help'
        require_relative 'cmd/debug'
        IRB::ExtendCommand::DebugCommand > @command_class || IRB::ExtendCommand::Help == @command_class
      end

      def evaluable_code
        # Hook command-specific transformation to return valid Ruby code
        if @command_class.respond_to?(:transform_args)
          arg = @command_class.transform_args(@arg)
        else
          arg = @arg
        end

        [@command, arg].compact.join(' ')
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
irb-1.11.2 lib/irb/statement.rb
irb-1.11.1 lib/irb/statement.rb
irb-1.11.0 lib/irb/statement.rb
study_line-0.1.6 vendor/bundle/ruby/3.2.0/gems/irb-1.8.3/lib/irb/statement.rb
study_line-0.1.5 vendor/bundle/ruby/3.2.0/gems/irb-1.8.3/lib/irb/statement.rb
study_line-0.1.4 vendor/bundle/ruby/3.2.0/gems/irb-1.8.3/lib/irb/statement.rb
study_line-0.1.3 vendor/bundle/ruby/3.2.0/gems/irb-1.8.3/lib/irb/statement.rb
irb-1.10.1 lib/irb/statement.rb
study_line-0.1.2 vendor/bundle/ruby/3.2.0/gems/irb-1.8.3/lib/irb/statement.rb
study_line-0.1.1 vendor/bundle/ruby/3.2.0/gems/irb-1.8.3/lib/irb/statement.rb
irb-1.10.0 lib/irb/statement.rb
irb-1.9.1 lib/irb/statement.rb
irb-1.9.0 lib/irb/statement.rb
irb-1.8.3 lib/irb/statement.rb
irb-1.8.2 lib/irb/statement.rb
irb-1.8.1 lib/irb/statement.rb
irb-1.8.0 lib/irb/statement.rb