# class Byebug::SaveCommand

Save current settings to use them in another debug session.

### Public Class Methods

description() click to toggle source

    # File lib/byebug/commands/save.rb, line 17
        def self.description
          <<-DESCRIPTION
            save[ FILE]

            #{short_description}

            Byebug state is saved as a script file. This includes breakpoints,
            catchpoints, display expressions and some settings. If no filename is
            given, byebug will fabricate one.

            Use the "source" command in another debug session to restore the saved
            file.
          DESCRIPTION
        end

regexp() click to toggle source

    # File lib/byebug/commands/save.rb, line 13
    def self.regexp
      /^\s* sa(?:ve)? (?:\s+(\S+))? \s*$/x
    end

short_description() click to toggle source

    # File lib/byebug/commands/save.rb, line 32
    def self.short_description
      "Saves current byebug session to a file"
    end

### Public Instance Methods

execute() click to toggle source

    # File lib/byebug/commands/save.rb, line 36
    def execute
      file = File.open(@match[1] || Setting[:savefile], "w")

      save_breakpoints(file)
      save_catchpoints(file)
      save_displays(file)
      save_settings(file)

      print pr("save.messages.done", path: file.path)
      file.close
    end

### Private Instance Methods

save_breakpoints(file) click to toggle source

    # File lib/byebug/commands/save.rb, line 50
    def save_breakpoints(file)
      Byebug.breakpoints.each do |b|
        file.puts "break #{b.source}:#{b.pos}#{" if #{b.expr}" if b.expr}"
      end
    end

save_catchpoints(file) click to toggle source

    # File lib/byebug/commands/save.rb, line 56
    def save_catchpoints(file)
      Byebug.catchpoints.each_key do |c|
        file.puts "catch #{c}"
      end
    end

save_displays(file) click to toggle source

    # File lib/byebug/commands/save.rb, line 62
    def save_displays(file)
      Byebug.displays.each { |d| file.puts "display #{d[1]}" if d[0] }
    end

save_settings(file) click to toggle source

    # File lib/byebug/commands/save.rb, line 66
    def save_settings(file)
      %w[autoirb autolist basename].each do |setting|
        file.puts "set #{setting} #{Setting[setting.to_sym]}"
      end
    end