Sha256: 855d47cacdd31f9a5628c20606e10151e41a03a26c1cdb25f5e3c8d4d2c7be4f

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

module Debugger
  class Command # :nodoc:
    class << self
      def commands
        @commands ||= []
      end
      
      DEF_OPTIONS = {
        :event => true, 
        :control => false, 
        :always_run => false,
        :unknown => false,
        :need_context => false,
      }
      
      def inherited(klass)
        DEF_OPTIONS.each do |o, v|
          klass.options[o] = v if klass.options[o].nil?
        end
        commands << klass
      end

      def load_commands
        dir = File.dirname(__FILE__)
        Dir[File.join(dir, 'commands', '*')].each do |file|
          require file if file =~ /\.rb$/
        end
      end
      
      def method_missing(meth, *args, &block)
        if meth.to_s =~ /^(.+?)=$/
          @options[$1.intern] = args.first
        else
          if @options.has_key?(meth)
            @options[meth]
          else
            super
          end
        end
      end
      
      def options
        @options ||= {}
      end
    end
    
    def initialize(state)
      @state = state
    end

    def match(input)
      @match = regexp.match(input)
    end

    protected

    def print(*args)
      @state.print(*args)
    end

    def confirm(msg)
      @state.confirm(msg) == 'y'
    end

    def debug_eval(str)
      begin
        val = eval(str, @state.binding)
      rescue StandardError, ScriptError => e
        at = eval("caller(1)", @state.binding)
        print "%s:%s\n", at.shift, e.to_s.sub(/\(eval\):1:(in `.*?':)?/, '')
        for i in at
          print "\tfrom %s\n", i
        end
        throw :debug_error
      end
    end

    def debug_silent_eval(str)
      begin
        eval(str, @state.binding)
      rescue StandardError, ScriptError
        nil
      end
    end

    def line_at(file, line)
      Debugger.line_at(file, line)
    end

    def get_context(thnum)
      Debugger.contexts.find{|c| c.thnum == thnum}
    end  
  end
  
  Command.load_commands
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-debug-0.5.2-mswin32 lib/ruby-debug/command.rb
ruby-debug-0.5.3 lib/ruby-debug/command.rb
ruby-debug-0.5.2 lib/ruby-debug/command.rb