module Byebug::ParseFunctions
def get_int(str, cmd, min = nil, max = nil)
min or max is nil, that value has no bound.
Parse 'str' of command 'cmd' as an integer between min and max. If either
def get_int(str, cmd, min = nil, max = nil) if str !~ /\A[0-9]+\z/ return nil, "\"#{cmd}\" argument \"#{str}\" needs to be a number" end int = str.to_i if min && int < min return nil, "\"#{cmd}\" argument \"#{str}\" needs to be at least #{min}" elsif max && int > max return nil, "\"#{cmd}\" argument \"#{str}\" needs to be at most #{max}" end int end
def get_line(filename, lineno)
Gets a single line in a source code file
def get_line(filename, lineno) lines = get_lines(filename) return nil unless lines lines[lineno - 1] end
def get_lines(filename)
Gets all lines in a source code file
def get_lines(filename) return nil unless File.exist?(filename) lines(filename) end
def lines(filename)
Fills SCRIPT_LINES__ entry for
def lines(filename) SCRIPT_LINES__[filename] ||= File.readlines(filename) end
def parse_steps(str, cmd)
is empty.
Returns the number of steps specified in
def parse_steps(str, cmd) return 1 unless str steps, err = get_int(str, cmd, 1) return nil, err unless steps steps end
def syntax_valid?(code)
Returns true if code is syntactically correct for Ruby.
def syntax_valid?(code) eval("BEGIN {return true}\n#{code}", nil, '', 0) rescue SyntaxError false end