lib/megahal/megahal.rb
# Save MegaHAL's brain to the specified binary file.
#
# @param [String] filename The brain file to be saved.
# @param [ProgressBar] bar An optional progress bar instance.
Save MegaHAL's brain to the specified binary file.
Save MegaHAL ' s brain to the specified binary file .
def save(filename, bar = nil)
    bar.total = 6 unless bar.nil?
    Zip::File.open(filename, Zip::File::CREATE) do |zipfile|
      zipfile.get_output_stream("dictionary") do |file|
        data = {
          version: 'MH11',
          learning: @learning,
          brain: @brain,
          dictionary: @dictionary
        }
        file.write(Marshal::dump(data))
      end
      bar.increment unless bar.nil?
      [:seed, :fore, :back, :case, :punc].each do |name|
        tmp = _get_tmp_filename(name)
        instance_variable_get("@#{name}").save(tmp)
        zipfile.add(name, tmp)
        bar.increment unless bar.nil?
      end
    end
  end
def save ( filename , bar = nil ) bar . total = 6 unless bar . nil? Zip :: File . open ( filename , Zip :: File :: CREATE ) do | zipfile | zipfile . get_output_stream ( "dictionary" ) do | file | data = { version : 'MH11' , learning : @learning , brain : @brain , dictionary : @dictionary } file . write ( Marshal :: dump ( data ) ) end bar . increment unless bar . nil? [ :seed , :fore , :back , :case , :punc ] . each do | name | tmp = _get_tmp_filename ( name ) instance_variable_get ( "@#{name}" ) . save ( tmp ) zipfile . add ( name , tmp ) bar . increment unless bar . nil? end end end
Save MegaHAL's brain to the specified binary file.
Save MegaHAL ' s brain to the specified binary file .
filename
bar
bar An optional progress bar instance.
bar An optional progress bar instance .