Module: Byebug::ParseFunctions

Defined in:
lib/byebug/helper.rb

Constant Summary collapse

Position_regexp =
'(?:(\d+)|(.+?)[:.#]([^.:\s]+))'

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.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/byebug/helper.rb', line 8

def get_int(str, cmd, min = nil, max = nil, default = 1)
  unless str
    return default if default
    print "You need to specify an argument for \"#{cmd}\"\n"
    return nil
  end

  begin
    int = Integer(str)
    if min and int < min
      print "\"#{cmd}\" argument \"#{str}\" needs to be at least #{min}\n"
      return nil
    elsif max and int > max
      print "\"#{cmd}\" argument \"#{str}\" needs to be at most #{max}\n"
      return nil
    end
    return int
  rescue
    print "\"#{cmd}\" argument \"#{str}\" needs to be a number\n"
    return nil
  end
end

#syntax_valid?(code) ⇒ Boolean

Return true if code is syntactically correct for Ruby.

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/byebug/helper.rb', line 32

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