Module: Debugger::ParseFunctions

Defined in:
lib/ruby-debug-ide/helper.rb

Instance Method Summary collapse

Instance Method Details

#get_int(str, cmd, min = nil, max = nil, default = 1) ⇒ Object

Parse ‘str’ of command ‘cmd’ as an integer between min and max. If either min or max is nil, that value has no bound.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby-debug-ide/helper.rb', line 7

def get_int(str, cmd, min=nil, max=nil, default=1)
  return default unless str
  begin
    int = Integer(str)
    if min and int < min
      print_error "%s argument '%s' needs to at least %s.\n" % [cmd, str, min]
      return nil
    elsif max and int > max
      print_error "%s argument '%s' needs to at most %s.\n" % [cmd, str, max]
      return nil
    end
    return int
  rescue
    print_error "%s argument '%s' needs to be a number.\n" % [cmd, str]
    return nil
  end
end

#syntax_valid?(code) ⇒ Boolean

Return true if code is syntactically correct for Ruby.

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/ruby-debug-ide/helper.rb', line 26

def syntax_valid?(code)
  eval("BEGIN {return true}\n#{code}", nil, "", 0)
rescue Exception
  false
end