| Module | Debugger::ParseFunctions |
| In: |
cli/ruby-debug/helper.rb
|
| Position_regexp | = | '(?:(\d+)|(.+?)[:.#]([^.:\s]+))' |
Parse ‘str’ of command ‘cmd’ as an integer between min and max. If either min or max is nil, that value has no bound.
# File cli/ruby-debug/helper.rb, line 14
14: def get_int(str, cmd, min=nil, max=nil, default=1)
15: return default unless str
16: begin
17: int = Integer(str)
18: if min and int < min
19: print "%s argument '%s' needs to at least %s.\n" % [cmd, str, min]
20: return nil
21: elsif max and int > max
22: print "%s argument '%s' needs to at most %s.\n" % [cmd, str, max]
23: return nil
24: end
25: return int
26: rescue
27: print "%s argument '%s' needs to be a number.\n" % [cmd, str]
28: return nil
29: end
30: end
Return true if arg is ‘on’ or 1 and false arg is ‘off’ or 0. Any other value raises RuntimeError.
# File cli/ruby-debug/helper.rb, line 34
34: def get_onoff(arg, default=nil, print_error=true)
35: if arg.nil? or arg == ''
36: if default.nil?
37: if print_error
38: print "Expecting 'on', 1, 'off', or 0. Got nothing.\n"
39: raise RuntimeError
40: end
41: return default
42: end
43: end
44: case arg.downcase
45: when '1', 'on'
46: return true
47: when '0', 'off'
48: return false
49: else
50: if print_error
51: print "Expecting 'on', 1, 'off', or 0. Got: %s.\n" % arg.to_s
52: raise RuntimeError
53: end
54: end
55: end
Return ‘on’ or ‘off’ for supplied parameter. The parmeter should be true, false or nil.
# File cli/ruby-debug/helper.rb, line 59
59: def show_onoff(bool)
60: if not [TrueClass, FalseClass, NilClass].member?(bool.class)
61: return "??"
62: end
63: return bool ? 'on' : 'off'
64: end