class Byebug::Setting

Parent class for all byebug settings.

Constants

DEFAULT

Attributes

value[RW]

Public Class Methods

[](name) click to toggle source
# File lib/byebug/setting.rb, line 45
def [](name)
  settings[name].value
end
[]=(name, value) click to toggle source
# File lib/byebug/setting.rb, line 49
def []=(name, value)
  settings[name].value = value
end
find(shortcut) click to toggle source
# File lib/byebug/setting.rb, line 53
def find(shortcut)
  abbr = /^no/.match?(shortcut) ? shortcut[2..-1] : shortcut
  matches = settings.select do |key, value|
    key =~ (value.boolean? ? /#{abbr}/ : /#{shortcut}/)
  end
  matches.size == 1 ? matches.values.first : nil
end
help_all() click to toggle source

@todo DRY this up. Very similar code exists in the CommandList class

# File lib/byebug/setting.rb, line 64
def help_all
  output = "  List of supported settings:\n\n"
  width = settings.keys.max_by(&:size).size
  settings.each_value do |sett|
    output += format(
      "  %<name>-#{width}s -- %<description>s\n",
      name: sett.to_sym,
      description: sett.banner
    )
  end
  output + "\n"
end
new() click to toggle source
# File lib/byebug/setting.rb, line 13
def initialize
  @value = self.class::DEFAULT
end
settings() click to toggle source
# File lib/byebug/setting.rb, line 41
def settings
  @settings ||= {}
end

Public Instance Methods

boolean?() click to toggle source
# File lib/byebug/setting.rb, line 17
def boolean?
  [true, false].include?(value)
end
help() click to toggle source
# File lib/byebug/setting.rb, line 27
def help
  prettify(banner)
end
integer?() click to toggle source
# File lib/byebug/setting.rb, line 21
def integer?
  Integer(value) ? true : false
rescue ArgumentError
  false
end
to_s() click to toggle source
# File lib/byebug/setting.rb, line 36
def to_s
  "#{to_sym} is #{value ? 'on' : 'off'}\n"
end
to_sym() click to toggle source
# File lib/byebug/setting.rb, line 31
def to_sym
  name = self.class.name.gsub(/^Byebug::/, "").gsub(/Setting$/, "")
  name.gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym
end